我正在通过禁用标准之一并自己管理所有内容来为活动创建自定义标题。我想知道是否可以根据我的需要替换/主题标准标题。
我可以通过更改 windowXYZStyle 项目通过主题自定义大小、背景图像和文本。
我唯一找不到的东西 - 我如何添加图像而不是文本。我已经尝试requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)
并分配自定义布局 - 但它似乎不起作用。
编辑:这是测试建议的报告,代码如下 - 结果 - 图像视图未显示。
活动
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
XML :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:paddingLeft="5dip"
android:background="@drawable/titlebar_bg"
android:layout_gravity="left|center"
>
<ImageView
android:id="@+id/logo"
android:src="@drawable/title_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>