zoukankan      html  css  js  c++  java
  • Android peferenceActivity 自己定义标题简单方法

    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的背景色之类

  • 相关阅读:
    List of the best open source software applications
    Owin对Asp.net Web的扩展
    NSwag给api加上说明
    'workspace' in VS Code
    unable to find valid certification path to requested target
    JMeter的下载以及安装使用
    exception disappear when forgot to await an async method
    Filter execute order in asp.net web api
    记录web api的request以及response(即写log)
    asp.net web api的源码
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5388597.html
Copyright © 2011-2022 走看看