我正在使用PreferenceActivity,如何設置自定義標題欄?不僅文本而且背景顏色,大小 - 整個佈局。在PreferenceAcivity中設置自定義標題欄
回答
PreferenceActivity extends ListActivity
,當你從XML與addPreferencesFromResource()
膨脹的喜好,它把東西到標準ListView
這ListActivity
用途。
所以基本上,你可以使用setContentView()
來指定一個佈局,但是你需要一個ListView
,它的編號爲"@+android:id/list"
。
因此,使用kleini的示例代碼:
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.login_settings);
setContentView(R.layout.login_settings_layout);
}
您需要在login_settings_layout.xml
一個ListView看起來像:
<ListView
android:id="@+android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
public class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
}
}
我試過,但沒有奏效。它不會改變任何東西。 – fhucho 2011-02-08 11:38:40
這不適用於PreferenceActivity,但適用於其他活動... – 2014-06-13 10:40:12
真棒,運行良好的 「NO_TITLE」:
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.login_settings);
setContentView(R.layout.login_settings_layout);
}
您可以發佈login_settings_layout.xml嗎? – fhucho 2011-05-04 12:50:12
或者這樣:
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitlebar);
addPreferencesFromResource(R.xml.preferences);
}
隨着customtitlebar .xml是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/customTitleBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/CustomWindowTitle">
</TextView>
本的方法爲我工作得很好!下面是代碼
public class PreferenceCustomTitleActivity extends PreferenceActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
/** Customize your background, textsize, cachetint, dividers
for your list view in the xml **/
setContentView(R.layout.layout_with_simple_listview_only);
ListView list = (ListView) findViewById(android.R.id.list);
View preferenceHeader = getLayoutInflater().inflate(
R.layout.preference_header, null);
list.addHeaderView(preferenceHeader);
}
}
這僅僅是爲我工作的事情。其餘的上述內容沒有在我的4.3 Nexus平板電腦上獲得理想的結果。
我無法真正重新創建適當的操作欄,像widget,但能夠在PreferenceActivity頂部放置一個大的「設置」標題,具有以下步驟。
我從另一個stackoverflow答案得到的提示,並只是使其更加詳細。
在PreferenceActivity類(刪除現有的標題欄)
public class Settings extends PreferenceActivity· { ... @Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); // This goes first super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings);
在res/XML/settings.xml中,我想提請注意第一PreferenceCategory
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:layout="@layout/settings_titlebar" /> <PreferenceCategory android:title="Notifications"> <Preference .....
在res/layout/settings_titlebar.xml中
Navals-的MacBook-PRO:ver_ui_0.2海軍$ VI RES /佈局/ settings_titlebar.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/header_background"
android:enabled="false">
<TextView android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@android:color/transparent"
android:padding="4dip"
android:text="Settings"
android:textSize="32sp"
/>
</RelativeLayout>
- 1. Android - 自定義標題欄
- 2. 自定義標題欄
- 3. 標題的自定義標題欄
- 4. Android設置自定義標題欄錯誤
- 5. 如何自定義標題欄在WPF
- 6. Android中的自定義標題欄
- 7. 自定義Java ME中的標題欄
- 8. Javafx 2.0中的自定義標題欄?
- 9. 自定義標題欄圖標 - Vista/Windows7
- 10. 自定義標題欄和標籤
- 11. 如何在android中動態設置自定義標題欄的TextView Value?
- 12. 自定義標題欄定位
- 13. 在自定義導航欄中設置欄按鈕項顏色
- 14. 自定義標籤欄設置了框和位置
- 15. 指標設計自定義搜索欄
- 16. 自定義標題欄 - Android崩潰
- 17. 安卓:自定義標題欄
- 18. PreferanceActivity和自定義標題欄。
- 19. Android自定義標題欄進度
- 20. 自定義標題欄和製表符
- 21. 自定義標題欄不工作android
- 22. 在magento家中設置自定義頁面標題
- 23. 在UITableView中設置自定義標題視圖
- 24. 如何在Phalcon控制器中設置自定義標題
- 25. 在IIS ISAPI篩選器中設置自定義標題值
- 26. 自定義標題欄 - 系統標題欄在短時間內顯示?
- 27. 在自定義工具欄中居中標題
- 28. 如何在rmarkdown的導航欄標題欄中添加自定義徽標?
- 29. 自定義配置設置問題
- 30. 如何設置自定義字體的標題工具欄的Android
`@ + android:id/list`應該是`@android:id/list` – mwieczorek 2016-07-10 09:15:12