【问题标题】:How to Change Height of Custom Dialog's Title Bar in Android如何在 Android 中更改自定义对话框标题栏的高度
【发布时间】:2011-10-25 13:36:56
【问题描述】:

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

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

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

【问题讨论】:

    标签: android titlebar


    【解决方案1】:

    是的,我刚刚检查过,你想使用"android:layout_height" 其他高度你也可以使用:"android:minHeight"

    【讨论】:

    • 我已经尝试过“android:layout_height”和“android:minHeight”,但标题栏的大小没有变化。这些属性会影响 Dialog Box 或其标题栏吗?就我而言,什么都没有发生
    • 您无法在本机中更改对话框中标题栏的高度,您必须创建自己的视图并将对话框的视图设置为您的自定义视图。这可以在这里完成:developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
    【解决方案2】:

    这对我有用

    你的主题:

      <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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多