如何自定义PreferenceActivity的标题? [英] How to customize the title of a PreferenceActivity?
本文介绍了如何自定义PreferenceActivity的标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有类似这个问题的问题: PreferenceActivity中的自定义标题栏?
I have the same problem like this question: Custom title bar in PreferenceActivity?
扩展PreferenceActivity
之后,我在onCreate()
中编写此代码,它只是显示一个空白的灰色标题.我认为这是一个错误(因为此解决方案适用于Activity).
After extending PreferenceActivity
, I write this code in onCreate()
, it just shows a blank grey title. I think it is a bug (because this solution works well with Activity).
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.main_pref);
已编辑:
window_title.xml
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="match_parent"
android:background="@color/titleBar"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip">
<ImageView android:id="@+id/imageView1"
android:src="@drawable/megadict_icon"
android:layout_height="35dip"
android:layout_width="35dip"
android:layout_gravity="center_vertical" />
<TextView android:layout_width="wrap_content"
android:id="@+id/textView1"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="16dip"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:text="@string/appName"
android:paddingLeft="5dip"
android:paddingRight="5dip" />
<ProgressBar style="?android:attr/progressBarStyleSmall"
android:id="@+id/progressBar"
android:layout_width="28dip"
android:layout_height="28dip"
android:layout_gravity="center_vertical"
android:visibility="invisible" />
</LinearLayout>
main_pref.xml
main_pref.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/mainPrefTitle">
<ListPreference android:entries="@array/languageStrings"
android:entryValues="@array/languageValues"
android:dialogTitle="@string/languagePrefTitle"
android:title="@string/mainPrefTitle"
android:key="languagePrefKey" />
</PreferenceScreen>
推荐答案
在addPreferenceFromResource()
之后致电setFeatureInt()
.
这篇关于如何自定义PreferenceActivity的标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文