在PreferenceScreen加入自定义布局
生活随笔
收集整理的這篇文章主要介紹了
在PreferenceScreen加入自定义布局
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
想在PreferenceScreen頁面加入一個(gè)自定義的布局,這里以加入一個(gè)button為例,記錄一下
加入一個(gè)自定義布局有兩種方式:
然后在your_custom_layou.xml文件中定一個(gè)button,你懂的!
在android:layout屬性指定你自定義的layout,注意preference的布局是定義在xml目錄下的
2. 定義一個(gè)layout布局文件且布局要包含ListView android:id="@android:id/list"
1)在layout目錄下單獨(dú)寫一個(gè)布局layout文件,定義你想要的布局,注意一定要包含ListView且id為@android:id/list,為要展示的perference占位
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><Button android:text="This is a button on top of all preferences."android:layout_width="wrap_content"android:layout_height="wrap_content" /><ListView android:id="@android:id/list"android:layout_width="match_parent"android:layout_height="wrap_content" /> </LinearLayout>2)然后在xml目錄下定義preference文件,preference文件不需要考慮自定義的布局
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"><Preferenceandroid:key="preference_key_you_want"android:title="preference_title_you_want"android:summary="preference_summary_you_want"android:layout="@layout/your_custom_layout"/> </PreferenceScreen>3)在PreferenceActivity中加入兩行代碼:
addPreferencesFromResource(R.xml.preferences); setContentView(R.layout.main);兩種方式在使用上的區(qū)別之一:
第二種方式可以不受perference的style影響
總結(jié)
以上是生活随笔為你收集整理的在PreferenceScreen加入自定义布局的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【毕设狗】【单片机毕业设计】基于单片机的
- 下一篇: 蓝牙厂商代码与公司对应列表