我正在创建自定义活动标题,禁用标准标题并自己管理一切。我想知道是否可以替换/主题标准标题以满足我的需要。
通过更改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>