【问题标题】:Android set height of custom title barAndroid设置自定义标题栏高度
【发布时间】:2012-06-07 13:05:17
【问题描述】:

我制作了一个自定义标题栏。标题栏中有两个相邻的图像视图和一个文本视图。它工作正常,但我只看到文本视图的顶部。所以我认为标题栏在底部被裁剪。有人知道如何设置自定义标题栏的高度吗? 编辑:我的自定义标题栏:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="45dip"
    android:orientation="vertical"
    android:id="@+id/header_root"> 
<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<ImageView
    android:id="@+id/header_image"
    android:layout_width="wrap_content"
    android:layout_height="27dip"
    android:src="@drawable/header_image"
    />

<ImageView
    android:id="@+id/options"
    android:layout_width="wrap_content"
    android:layout_height="27dip"
    android:layout_margin="-8dip"
    android:layout_toRightOf="@+id/header_image"
    android:src="@drawable/options" />

</RelativeLayout>
<TextView 
    android:text="Vissenencyclopedie"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="15dp"
    android:id="@+id/titel"
    android:layout_marginTop="-7dip"
    />
</LinearLayout>  

【问题讨论】:

  • 如果您可以粘贴自定义标题栏的 xml,解决此问题会更容易。
  • 好的。我编辑了我的问题

标签: android height titlebar


【解决方案1】:

使用风格:

 <style name="CustomTheme" parent="@android:style/Theme.Light">
    <item name="android:windowTitleSize">30dp</item>
</style>

并添加到清单中:

 <activity
        android:name=".MainActivity"
        android:theme="@style/CastomTheme" >
 </activity>

【讨论】:

  • 正确解决方案!如果您想更进一步并添加自定义背景颜色/图像,请参见此处:stackoverflow.com/a/2285722/1208581
  • 谢谢。拼写 android:theme="@style/CastomTheme" -> android:theme="@style/CustomTheme"
【解决方案2】:

我认为问题在于您为外部 LinearLayout 指定的 android:layout_height="45dip"。将该行替换为android:layout_height="wrap_content",我想这会解决您的问题。

【讨论】:

    【解决方案3】:

    我假设标题栏在某种布局中,所以你可以做的是设置布局的高度,例如:

    android:height="30dp"
    

    您还可以为文本视图提供填充,例如:

    android:paddingBottom="10dp"
    

    这应该确保显示文本。希望这会有所帮助。

    【讨论】:

    • 嗯,它没有。我已经试过了。当我查看自定义标题栏的图形布局时,它会正确显示标题栏。但是当我在模拟器上运行应用程序并使用此自定义布局进入活动时,文本视图被裁剪。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多