如何更改 Android 中自定义对话框标题栏的高度

发布于 2024-12-11 16:41:35 字数 390 浏览 1 评论 0原文

在我的 Android 应用程序中,我有一个自定义对话框。我想设置对话框标题栏的高度。我的风格如下:

<resources>
    <style name="customDialogStyle" parent="android:Theme.Dialog"> 
        <item name="android:background">#04a9ee</item>
        <item name="android:height">5dp</item> 
     </style> 
</resources>

但是标题栏上的“高度”属性没有效果。那么,如何改变自定义对话框标题栏的高度呢?

In my android app I have a custom dialog box. I want to set the height of dialog's Title bar. My style is as follows:

<resources>
    <style name="customDialogStyle" parent="android:Theme.Dialog"> 
        <item name="android:background">#04a9ee</item>
        <item name="android:height">5dp</item> 
     </style> 
</resources>

But there is no effect of "height" attribute on title bar. So, how can the height of custom dialog's title bar can be changed ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泡沫很甜 2024-12-18 16:41:35

是的,我只是检查一下,您想使用 "android:layout_height" 您也可以使用其他高度,例如:"android:minHeight"

Yeh I just check, you want to use "android:layout_height" other heights you can use also like: "android:minHeight"

枕梦 2024-12-18 16:41:35

这对我有用

你的主题:

  <resources>
       <style name="MyDialog" parent="android:Theme.Holo.Dialog">
           .......

       </style>

  </resources>

你的自定义对话框类:

  public class CustomDialog extends Dialog
  {
       public CustomDialog(Context context, int theme) {
           super(context, theme);
       }


       @Override
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          ........... 

          Resources res = getContext().getResources();
          int titleId = res.getIdentifier("title", "id", "android");
          View title = findViewById(titleId);
          if (title != null) {
              title.getLayoutParams().height = 5; // your height
          }
       }
  }

创建对话框并在代码中显示:

   CustomDialog customDialog = new CustomDialog(this, R.style.MyDialog);
   customDialog.show();

This works for me

Your theme:

  <resources>
       <style name="MyDialog" parent="android:Theme.Holo.Dialog">
           .......

       </style>

  </resources>

Your Custom Dialog Class:

  public class CustomDialog extends Dialog
  {
       public CustomDialog(Context context, int theme) {
           super(context, theme);
       }


       @Override
       protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          ........... 

          Resources res = getContext().getResources();
          int titleId = res.getIdentifier("title", "id", "android");
          View title = findViewById(titleId);
          if (title != null) {
              title.getLayoutParams().height = 5; // your height
          }
       }
  }

Create dialog and show in your code:

   CustomDialog customDialog = new CustomDialog(this, R.style.MyDialog);
   customDialog.show();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文