`
wsqwsq000
  • 浏览: 676199 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

How to add a button to PreferenceScreen

 
阅读更多

There is another solution for customizing the appearance of the preferences.

Design a normal XML layout with buttons or whatever you want to add to the standard preferences. Include a ListView in your layout and give it the ID @android:id/list.

Let's say we call the layout file res/layout/main.xml. It could look something like this:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
              android:layout_width="fill_parent" 
              android:layout_height="fill_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="fill_parent" 
              android:layout_height="fill_parent" /> 
</LinearLayout> 

In your PreferenceActivity, add these two lines to your onCreate:

addPreferencesFromResource(R.xml.preferences); 
setContentView(R.layout.main); 
The ListView in your layout will then be replaced by the preferences defined the usual way in res/xml/preferences.xml
分享到:
评论

相关推荐

    安卓PreferenceScreen使用详细Demo

    安卓PreferenceScreen使用详细Demo,本Demo对应博文https://blog.csdn.net/qXing123456789/article/details/84962172

    android 设置界面 PreferenceScreen

    android 设置界面偏好设置,里面包括基础用法和自定义Preference举例

    android几个经典的效果实现

    集合了几个经典的效果实现。... 2、自定义位置和样式的半透明对话框,实现悬浮...6、preferenceScreen实现设置效果。 7、spanableString设置超链接,字体,颜色等效果实现。 学习android应用开发的可以参考一下,很有用的。

    Android设置PreferenceCategory背景颜色的方法

    大家可能遇到,PreferenceCategory默认是黑色背景,如何我们更换了PreferenceScreen的背景,那么这种分隔栏看上去很丑,那么怎么更改背景呢?我们可以通过自定义VIEW来实现。 代码如下: public class ...

    Android中删除Preference详解

    声明简单,但是如何从PreferenceScreen或者PreferenceCategory中删除一个Preference会简单么.为什么有些人写的就无法删除成功呢?本文将从Android源码实现来分析一下. 声明文件 代码如下: &lt;?xml version=”1.0″ ...

    未接来电提醒 源码

    使用PreferenceScreen控件 继承ListPreference的MutiSelectListPreference,可以多选

    android2.3.5 CDMA/EVDO拨号APN解决方案

    google提供的android2.3里面,只能在GSM/WCDMA情况下才能从“设置”-&gt;“无线和网络”-&gt;“移动网络”-&gt;“接入点名称”中选择不同的...PreferenceScreen android:key=”button_apn_key” android:title=”@string/apn_se

    PreferenceApp:这个演示应用程序如何使用PreferenceFragmentCompat

    使用xml的喜好包含文件PreferenceScreen与和内PreferenceScreen 处理PreferenceScreen打开 处理方向更改而无需在片段上保留实例或锁定Activity 处理android后退按钮以转到上一个屏幕 待办的。 去做 汉德回到首页...

    android 设置1

    今天主要研究了一下设置中的Preferencescreen应用,它不仅可以作为设置界面显示,而且还能够启动activity,下面主要是对启动activity的介

    prefs-plus:Android 首选项扩展

    偏好+ Android 首选项的扩展,可创建其他首选项类型,包括EditIntPreference 、 EditFloatPreference...用法首选项.xml &lt; PreferenceScreen xss=removed&gt; &lt; com .mapzen.prefsplus.EditIntPreference android

    Shine:应用程序了解android平台的详细信息

    闪耀 应用程序了解android平台的详细信息 #发现路线图 HttpUrlConnection ...通过首选项xml文件并使用根元素PreferenceScreen-以及其他子元素(如EditTextPreference,ListPreference)来制作首选项,它

    Android布局——Preference自定义layout的方法

    正文:首先PreferenceScreen是一个xml文件于res/xml目录下,不属于layout文件。要插入layout,有两种方法。 1.使用Preference的android:@layout属性 1)xml文件中preference的添加 代码如下: &lt;Preference android...

    ShowCaseAndroid:android 应用程序的自动化“ShowCase”和“Tips Baloons”

    ShowCaseAndroid android 应用程序的自动化“ShowCase”和“Tips Baloons” 已知的问题 contentDescription 属性,在 PreferenceScreen' xml 中定义,被 android 忽略,因此只有 xml 定义的提示有效

    Android SubSettings跳转

    Android SubSettings跳转 &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" &gt; android:key="settings" ...&lt;/PreferenceScreen&gt;

    材质偏好设置:可以更轻松地在之前的棒棒糖设备上创建偏好屏幕,看起来就像是棒棒糖一样

    带工具栏的嵌套PreferenceScreen和处理配置正确更改(恢复状态) 没有API更改(仅用于技巧) 安装(Gradle依赖) compile 'com.fnp:material-preferences:0.1.4' 用法 请检查和下面的必需步骤。 样式 对于棒棒糖...

Global site tag (gtag.js) - Google Analytics