今天在修改系统代码的时候,系统代码用了PreferenceActivity,出于某种需求,我想把布局PreferenceScreen整个的嵌套在我的一个正常的layout xml中,就好像把PreferenceScreen 作为一个普通的view使用如button一样随便放,开始以为不可行 后来终于找到了替换办法 那就是 把要PreferenceScreen嵌入的地方用一个
<ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" />
作为占位符 就可一了
PreferenceScreen 布局保持不变
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/settings"> <PreferenceCategory android:title="@string/clock_settings"> <!-- <ListPreference android:key="clock_style" android:title="@string/clock_style" android:entries="@array/clock_style_entries" android:entryValues="@array/clock_style_values" android:defaultValue="@string/default_clock_style" android:dialogTitle="@string/clock_style" /> --> <CheckBoxPreference android:key="automatic_home_clock" android:title="@string/automatic_home_clock" android:summary="@string/automatic_home_clock_summary" android:defaultValue="true" /> <ListPreference android:key="home_time_zone" android:entries="@array/timezone_labels" android:entryValues="@array/timezone_values" android:dialogTitle="@string/home_time_zone_title" android:title="@string/home_time_zone" /> </PreferenceCategory> <PreferenceCategory android:title="@string/alarm_settings"> <ListPreference android:key="auto_silence" android:title="@string/auto_silence_title" android:entries="@array/auto_silence_entries" android:entryValues="@array/auto_silence_values" android:defaultValue="10" android:dialogTitle="@string/auto_silence_title" /> <com.haier.deskclock.SnoozeLengthDialog android:key="snooze_duration" android:title="@string/snooze_duration_title" android:defaultValue="10"/> <VolumePreference android:title="@string/alarm_volume_title" android:dialogTitle="@string/alarm_volume_title" android:persistent="false" android:streamType="alarm" /> <ListPreference android:key="volume_button_setting" android:title="@string/volume_button_setting_title" android:dialogTitle="@string/volume_button_setting_title" android:entries="@array/volume_button_setting_entries" android:entryValues="@array/volume_button_setting_values" android:defaultValue="0" /> </PreferenceCategory> </PreferenceScreen>
上面是settings.xml
下面是我最终想要显示的程序
<?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:background="@drawable/setting_bg" android:orientation="horizontal"> <RelativeLayout android:layout_width="160dip" android:layout_height="match_parent" android:background="@drawable/toolbarbg" android:paddingTop="30dip"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/toolbar_screen_home" android:layout_alignParentTop="true" android:background="@drawable/toolbar_home" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/toolbar_screen_back" android:layout_below="@id/toolbar_screen_home" android:background="@drawable/toolbar_back" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/toolbar_setting" android:layout_alignParentBottom="true" android:background="@drawable/toolbar_home" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/toolbar_add" android:layout_above="@id/toolbar_setting" android:background="@drawable/toolbar_home" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="130dip" android:background="@drawable/titlebar" android:paddingTop="15dip" android:paddingLeft="30dip" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Setting - Alarm" android:gravity="left" android:textColor="#fdb200" android:textSize="30sp" android:id="@+id/setting_text"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="设置 - 闹钟" android:shadowColor="#000000" android:shadowDy="4" android:gravity="left" android:textColor="#fff6ce" android:textSize="30sp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </LinearLayout> </LinearLayout>
一定要注意listview 还有他的id
然后调用
addPreferencesFromResource(R.xml.settings); setContentView(R.layout.setting_main);
相关推荐
android PreferenceActivity中的组件源码~
雨松MOMO带你做软件 Android软件开发之PreferenceActivity中组件的使用 ,欢迎大家下载阅读 哇咔咔~~
使用 PreferenceActivity设置个性信息, 参考:android 设置类PreferenceActivity http://blog.csdn.net/xiaobijia/article/details/41479235
PreferenceActivity用法简介 Android X
android中PreferenceActivity详解
NULL 博文链接:https://2528.iteye.com/blog/1049177
自定义PreferenceActivity,达到自己想要的ui效果
仿IOS的PreferenceActivity界面,素材来自新浪微博,相关博文:http://www.cnblogs.com/tianzhijiexian/p/3893504.html
Android之PreferenceActivity简介,Android之PreferenceActivity简介
自定义PreferenceActivity的样式,相关博客:http://www.cnblogs.com/tianzhijiexian/p/3892506.html
这个示例 PreferenceActivity 类的用法,它可以保存设置
NULL 博文链接:https://topmanopensource.iteye.com/blog/1291071
看到很多书中都没有对PreferenceActivity做介绍,而我正好又在项目中用到,所以就把自己的使用的在这总结一下,也方便日后查找。PerferenceActivity是什么,看下面的截图: Android系统截图(左) ...
NULL 博文链接:https://justwyy.iteye.com/blog/1338864
很想做个天气预警的功能, 想用preferences来做界面。 看了很多preferences感觉定制性太差 所以自己做了一个。 应该是不错的demo 定制preferences在preferencesActivity中的布局 和自定义了对话框的布局
这个是我将设置中的PreferenceActivity修改成Activity的过程,本dome是以 WifidisplayActivity为例子。
最近研究了Android Setting中源码部分,发现大多视图显示部分大多采用的是Preference,所以我修改了系统设置中的一个界面希望能帮助到大家
android老知识了,有个老项目回顾一个PreferenceActivity