我已经按照这个 SO 问题的说明进行操作:How to change the text on the action bar
我能够成功地创建自己的标题栏,但是当我将背景颜色应用于我的布局时,该颜色不会跨越整个标题栏。 android 灰色背景颜色仍然存在。
这是我的 XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400px"
android:layout_height="fill_parent"
android:orientation="horizontal" android:background="@color/solid_blue">
<ImageView android:id="@+id/logo"
android:layout_width="57px"
android:layout_height="wrap_content"
android:background="@drawable/icon">
</ImageView>
<TextView
android:id="@+id/myTitle"
android:text="StockDroid by"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#FFFFFF"
/>
</LinearLayout>
最佳答案
编辑:
您错过了为窗口标题设置自定义样式并通过 Activity 的 android:theme
属性在 list 中设置它的东西。
您必须在 res/values/styles.xml 文件中创建这两种样式:
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">50px</item>
<item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground
</item>
</style>
<style name="WindowTitleBackground" parent="android:WindowTitleBackground">
<item name="android:background">@android:color/transparent
</item>
</style>
然后你必须在你的 list 中将你的风格设置为主题,就像:
<activity android:name=".activity"
android:label="@string/appname" android:theme="@style/MyTheme" />
希望对您有所帮助。
关于java - 如何设置标题栏的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3776026/