如何将按钮添加到 PreferenceScreen [英] How to add a button to PreferenceScreen

查看:38
本文介绍了如何将按钮添加到 PreferenceScreen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以在首选项屏幕底部添加一个按钮并使其在滚动时正常工作?

Is there any way to add a button to the bottom of preferences screen and make them work correct when scrolling?

推荐答案

还有另一种自定义首选项外观的解决方案.

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

使用按钮或您想添加到标准首选项的任何内容设计一个普通的 XML 布局.在您的布局中包含一个 ListView 并为其指定 ID @android:id/list.

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.

假设我们调用布局文件 res/layout/main.xml.它可能看起来像这样:

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="match_parent"
              android:layout_height="match_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="match_parent"
              android:layout_height="wrap_content" />
</LinearLayout>

在您的 PreferenceActivity 中,将这两行添加到您的 onCreate 中:

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

addPreferencesFromResource(R.xml.preferences);
setContentView(R.layout.main);

布局中的 ListView 将被替换为 res/xml/preferences.xml 中通常定义的首选项.

The ListView in your layout will then be replaced by the preferences defined the usual way in res/xml/preferences.xml.

这篇关于如何将按钮添加到 PreferenceScreen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆