我有一个带有图标化文本的列表活动,我正在给它一个自定义标题。这是我的 custom_style.xml:
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#222222</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">50dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
这是标题的布局,window_title.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:background="#222222">
<ImageView
android:id="@+id/header"
android:src="@drawable/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
我在 onCreate 中设置了新的标题样式:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// if it wasn't a listactivity, here I'd use
// setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
browseToRoot();
}
我的问题是样式标题栏以正确的大小和正确的背景颜色显示(取自 custom_style.xml),但 window_title.xml 中的所有内容都被忽略了。listadapter 的其余部分仍然可以正常工作。这里有一个非常相似的问题:Custom title with image它说 setFeatureInt must come before super.onCreate 但无论哪种方式我的结果都是一样的。
我尝试用一个漂亮的简单文本视图替换 imageview,但整个 window_title.xml 似乎被忽略了。有什么想法我哪里出错了吗?非常感谢,巴兹。