Android peferenceActivity 自己定义标题简单方法

peferenceActivity 全然使用定义好的布局。

因此不能简单象其他好窗体进行自定,如今我们须要加

一个自己定义标题,比方象其他窗体一样加一个统一topbar.

如果这个topbar的布局是 title.xml

一.标准自己定义标题栏方法

Android 提供自己定义标题栏方法

我们简单实现。

@Override

protected void onCreate(Bundle savedInstanceState) {

final boolean isCustom =requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

super.onCreate(savedInstanceState);

setContentView(R.layout.tab_setting);

addPreferencesFromResource(R.xml.setting_preference);

if(isCustom)

getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);

可是在Android 4.0会提示

You cannot combine custom titles with other title features

网上提供非常多复杂办法解决,关键在PerferenceActivtiy 总是失败。

二.自己定义一个perfence 布局并作为第一个配置项。

在xml/perference.xml 布局文件下增加一个

<Preference android:layout="@layout/title" android:key="app_info"/>

这样在能够实现伪标题栏,这样的方法布局缺点是无法铺满整个窗体。即在布局两側会出一个白边,很不好看。

三.建一个自己定义窗体布局

在查询资料发现,perferenceActivity是能够支持全然的自己定义布局的。仅仅要保证布局中一个listView,它的id是

android:id="@android:id/list" 就可以

在调用addPreferencesFromResource(); 后,perference列表会自己主动增加到这个listView其中。而标题布局。简单加个在listView之上就可以。

这是成功的布局,效果很令人惬意。

<?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" android:background="@color/bg_color" >



<include android:id="@+id/title" layout="@layout/title"></include>

<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:cacheColorHint="@color/transparent" android:scrollbarStyle="outsideOverlay" android:fadingEdgeLength="0dp" android:scrollbars="none" android:fadingEdge="none"
android:listSelector="#00000000" />

</LinearLayout>

并且这个还会带来额外的优点是,能够自己定义perference list的背景色之类

最新文章

  1. C#汉字转拼音(npinyin)将中文转换成拼音全文或首字母
  2. MVC5+EF6 入门完整教程
  3. IIS与Apache共用80端口方法
  4. mysql连接报错 Host &lsquo;xxx&rsquo;is blocked because of many connection errors;unblock with 'mysqladmin flush-hosts'
  5. NVelocity学习笔记一——linq2sql+NVelocity完整demo
  6. zjoi2016 day1【bzoj4455】【bzoj4456】
  7. css初始化样例代码
  8. HTML中IFrame父窗口与子窗口相互操作
  9. maven学习(4)-本地项目打包发布到私有仓库
  10. CSS3 关于@font-face引用中文字体解决办法
  11. jquery IE6 select.val() bug报错解决办法
  12. poj3254(状压dp)
  13. Hibernate映射乱码
  14. Centos查看系统CPU个数、核心数、线程数
  15. flask session
  16. js判断空字符串、null、undefined、空格、中文空格
  17. Feign服务消费者
  18. openlayer3之高级标注实现
  19. linux&amp;php:ubuntu安装php-7.2
  20. ZOJ 1456 Minimum Transport Cost(floyd+后继路径记录)

热门文章

  1. maven学习--生命周期
  2. UVA10212 【The Last Non-zero Digit.】
  3. 触发器中的inserted表和deleted表
  4. Shell学习笔记:#*、%*字符串掐头去尾方法
  5. 2016-2017-2 20155309南皓芯java第四周学习总结
  6. Windows开机自动启动pageant,方便使用ssh链接到GitHub
  7. 关于URL编码(针对URL含有中文的参数)
  8. 丑数(UVa136)
  9. Codeforces Round #146 (Div. 1) C - Cyclical Quest 后缀自动机+最小循环节
  10. Python 多线程 实例