zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    Vue部署到相对目录和解决刷新404的问题
    JavaScript时间格式转换
    在Vue中使用Chart.Js
    进制转换和大数除法
    esp8266必备知识
    php 添加 freetype支持
    Linux系统时间同步问题
    busybox date 时间的加减
    kubesphere-wokespaces
    添加系统环境变量
  • 原文地址:https://www.cnblogs.com/kevincode/p/3840203.html
Copyright © 2011-2022 走看看