标签: preferencescreen

嵌套的偏好屏幕失去了主题

我有一个我的应用程序的首选项屏幕,在清单中我给它一个主题使用:

android:theme="@android:style/Theme.Light.WallpaperSettings"
Run Code Online (Sandbox Code Playgroud)

但是,当我在其中嵌入另一个首选项屏幕时,例如:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:title="@string/setting_title"
    android:key="...">

    <PreferenceCategory
    android:title="@string/title_themes"
    >

    <PreferenceScreen
    android:title="@string/title_themes_opt"
    >

        <ListPreference
    android:key="Setting_BG"
    android:title="@string/setting_bg"
    android:summary="@string/setting_bg_summary"
    android:entries="@array/bg_titles"
    android:defaultValue="0"
    android:entryValues="@array/bg_values" />
    </PreferenceScreen>

    </PreferenceCategory>

</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

嵌套的首选项屏幕会丢失父级的主题.如何防止这种情况?提前致谢.

android preferences preferencescreen

8
推荐指数
1
解决办法
2977
查看次数

如何以编程方式将EditTextPreferences添加到我的PreferenceFragment?

我是Android的新手,所以我需要一些关于如何以编程方式EditTextPreference对象添加到PreferenceFragment的指导.

我从Web服务中提取值列表.我已将它们成功保存到我的SharedPreferences中,并使用它们生成URL(路径部分).

我希望我的应用程序的用户能够编辑这些值,但在Google上进行大量搜索之后,我不清楚如何以编程方式EditTextPreference对象添加到我的PreferenceFragment中.

请注意,我的PreferenceFragment适用于SharedPreferences值,我将其作为名称硬编码到首选项xml文件(PreferenceScreen)中.我也知道如何获取我的SharedPreferences,所以不要担心必须向我解释这部分.

我在PreferenceFragment的onCreate中使用addPreferencesFromResource.我应该在onCreateView中添加它们吗?我以为我可以获得PreferenceCategory并在那里添加它们?但同样,我不知道该怎么做.我真的很感激你的帮助!

//代码

PrefsFragment.java:
package com.example.lorddoineedhelp;

import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class PrefsFragment extends PreferenceFragment {
  @Override
  public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   addPreferencesFromResource(R.xml.preferences); 
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = super.onCreateView(inflater, container, …
Run Code Online (Sandbox Code Playgroud)

android preferencescreen edittextpreference

8
推荐指数
2
解决办法
7495
查看次数

动态更改Custom PreferenceScreen的数据

我正在进行自定义PreferenceScreen,我已经使用设置页面创建了自定义屏幕PreferenceActivity.

以下是我的偏好屏幕.

在此输入图像描述

问题: - 我需要动态更改下载数据的徽章.我按照这个问题来实现这个布局.我已经尝试过这个问题的所有答案,但没有单独回答.

有没有其他方法可以找到哪个内部偏好?

的settings.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<Preference android:title="@string/settings_user_profile" android:key="user_profile" android:summary="@string/settings_user_profile_desc" android:layout="@layout/setting_list"></Preference>
<Preference android:title="@string/settings_download" android:key="download_data" android:summary="@string/settings_download_desc" android:layout="@layout/setting_list"></Preference>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

android android-preferences preferencescreen

7
推荐指数
1
解决办法
3762
查看次数

如何在Android应用程序中围绕PreferenceActivity包装DrawerLayout?

我正在编写一个Android应用程序来利用抽屉布局功能.我希望能够使用抽屉布局作为整个应用程序中可用的导航工具.要使用抽屉布局,我在我的活动布局xml文件中使用以下内容:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- The main content view -->
    <LinearLayout
        android:id="@+id/main_content_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The navigation drawer -->
    <ListView android:id="@+id/navigational_drawer"
        android:layout_width="220dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#FFFFFF"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

但是,围绕PreferenceActivity包装DrawerLayout我遇到了很多困难.PreferenceActivity是一种特殊的活动,我想保留它,因为它可以帮助我在我的应用程序中保持Android首选项的外观和感觉; 话虽如此,它使用addPreferencesFromResource()调用来加载首选项,并且不使用addContentView()调用来加载XML文件; 首选项资源通常包含不喜欢包装在DrawerLayouts中的PreferenceScreen标记.

任何人都必须处理这个问题,你是如何解决的?如果您的Android应用中有PreferenceActivity,并且您在同一活动中有DrawerLayout,请分享您是如何做到的.任何帮助将非常感激.

编辑:如果我改变

<!-- The main content view -->
<LinearLayout
    android:id="@+id/main_content_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
Run Code Online (Sandbox Code Playgroud)

<ListView 
     android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" />
Run Code Online (Sandbox Code Playgroud)

加载PreferenceActivity时应用程序不会崩溃(因为id"list"与Preference Activity期望找到的匹配); 然而,抽屉没有显示.这几乎就像ListView"列表"下面的所有内容都被忽略了一样.

android preferenceactivity preferencescreen drawerlayout

7
推荐指数
1
解决办法
2297
查看次数

PreferenceScreen - <intent ... /> - 异常 - FLAG_ACTIVITY_NEW_TASK

我是android开发的新手.

该项目是关于使用AbstractThreadedSyncAdapter实现AbstractAccountAuthenticator,以将服务器上的某些数据与内容提供程序同步.

我做了一切,添加帐户和同步都运行没有任何问题.

现在我尝试添加一个Preference-Screen,就像在android参考中一样建议(搜索AbstractAccountAuthenticator,它在那里解释)来自xml,如下所示:

autenticator.xml:

<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
    android:accountType="typeOfAuthenticator"
    android:icon="@drawable/icon"
    android:smallIcon="@drawable/miniIcon"
    android:label="@string/label"
    android:accountPreferences="@xml/account_preferences"
 />
Run Code Online (Sandbox Code Playgroud)

Preference-Screen-xml看起来像这样:

account_preferences.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 <PreferenceCategory android:title="@string/pref_cat_general">
  <PreferenceScreen android:key="@string/pref_cat_scr_keygen" android:title="@string/pref_cat_scr_keygen_title" android:summary="@string/pref_cat_scr_keygen_summary">
   <intent android:action="android.intent.action.VIEW" android:targetPackage="com.android.clean" android:targetClass="com.android.clean.KeygenAct" />
  </PreferenceScreen>
 </PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

屏幕应该是它应该如何,但这就是问题:当我点击PreferenceScreen意图导致系统崩溃(在模拟器和我的HTC-Desire中).

Logcat说:

ERROR/AndroidRuntime(18754):android.util.AndroidRuntimeException:从Activity上下文外部调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志.这真的是你想要的吗?

(整个Logcat on pastebin)

这里是清单的一部分,其中定义了活动:

<activity android:name=".KeygenAct">
    <intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

整个测试代码(这是我找到问题的基本要点的项目)是在googlecode(http://code.google.com/p/cleanproject/source/browse/)上找到(Eclipse-Project)

谢谢你的帮助,Esentian

ps:keygen不是密钥生成器,它意味着更多key_general.有点不好意思;)

xml android exception account-management preferencescreen

6
推荐指数
1
解决办法
6645
查看次数

Android:如何通过xml中的操作栏从首选项子屏幕导航回来?

我有一个现代的SettingsActivity使用PreferenceFragement.我完全用XML定义了它的布局.在我的设置中,我有一个偏好子屏幕.点击它PreferenceScreen会显示一个新的.

因为看起来我只能使用后退按钮导航回主设置屏幕.有没有办法ActionBar在子屏幕中启用导航?我更喜欢通过XML启用它.

在此先感谢,高粱

编辑:

我想在右侧像左侧一样:

在此输入图像描述

以下是Google的相应代码段:

<PreferenceScreen  xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- opens a subscreen of settings -->
    <PreferenceScreen
        android:key="button_voicemail_category_key"
        android:title="@string/voicemail"
        android:persistent="false">
        <ListPreference
            android:key="button_voicemail_provider_key"
            android:title="@string/voicemail_provider" ... />
        <!-- opens another nested subscreen -->
        <PreferenceScreen
            android:key="button_voicemail_setting_key"
            android:title="@string/voicemail_settings"
            android:persistent="false">
            ...
        </PreferenceScreen>
        <RingtonePreference
            android:key="button_voicemail_ringtone_key"
            android:title="@string/voicemail_ringtone_title"
            android:ringtoneType="notification" ... />
        ...
    </PreferenceScreen>
    ...
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)

xml navigation android preferencescreen android-actionbar

6
推荐指数
1
解决办法
4004
查看次数

自定义首选项 Android Kotlin

我想子类化Preference以在 Kotlin 中创建自定义首选项。我无法让自定义首选项在首选项屏幕中膨胀。如果我从我的首选项屏幕中删除这个自定义首选项,我实现的其余首选项(此处未显示)工作正常。 还有很多类似的表面上的问题在这里,但没有那些我已经找到了直接处理创建科特林实现自定义偏好的问题。

请帮助我提供一个您已经测试过的工作示例,该示例显示了三件事:

  1. custom_preference.xml
  2. CustomPreference.kt
  3. preference_screen.xml (显示自定义首选项的父首选项屏幕)

这是我的代码:一个xml显示字符串的自定义首选项(让我们在示例中保持简单,尽管我的首选项最终会具有更多的功能)

custom_preference.xml

<Preference 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@android:id/widget_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CustomPreference">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="This is a custom preference" />
</Preference>
Run Code Online (Sandbox Code Playgroud)

一个扩展Preference并包含适当构造函数的类。

自定义首选项.kt

package com.example.myApp

import android.content.Context
import android.support.v7.preference.Preference
import android.support.v7.preference.PreferenceViewHolder
import android.util.AttributeSet
import com.example.myApp.R
import com.example.myApp.R.layout.custom_preference

class CustomPreference (context: Context,
                            attrs: AttributeSet? = null,
                            defStyleAttr: Int = R.attr.preferenceStyle,
                            defStyleRes: Int = defStyleAttr)
    : Preference(context, attrs, defStyleAttr, defStyleRes) {
    override …
Run Code Online (Sandbox Code Playgroud)

android android-preferences preferencescreen kotlin android-recyclerview

6
推荐指数
1
解决办法
3219
查看次数

在 Android 的“PreferenceScreen”中调整边距/填充

我想调整 Android 中“PreferenceScreen”的默认边距/填充值,我知道不可能简单地在 XML 代码(布局文件)中设置它,但 Android 肯定会从某个地方获取这些值,并且可能(我希望)我可以设置一些“样式属性”并实现它。

我要调整的值是:

在此输入图像描述

我在网上找到了这个答案: Android:如何最大化 PreferenceFragment 宽度(或摆脱边距)?

但对我来说,它确实使用了一个非常糟糕的解决方法,我想尝试操纵一些官方参数。

有谁知道如何通过调整样式或其他一些字段来实现它?

android android-preferences preferencescreen android-styles android-settings

5
推荐指数
1
解决办法
3680
查看次数

首选项屏幕为白色

我尝试学习 Android 并决定创建 SettingsActivity。但我遇到的问题是我在 PreferenceScreen 上看不到任何文本。我的 PreferenceScreen 在设计模式下是白色的,所以我看不到那里的任何文本。

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <PreferenceCategory app:title="@string/messages_header">

        <EditTextPreference
            app:key="signature"
            app:title="@string/signature_title"
            app:useSimpleSummaryProvider="true" />

        <ListPreference
            app:defaultValue="reply"
            app:entries="@array/reply_entries"
            app:entryValues="@array/reply_values"
            app:key="reply"
            app:title="@string/reply_title"
            app:useSimpleSummaryProvider="true" />

    </PreferenceCategory>

    <PreferenceCategory app:title="@string/sync_header">

        <SwitchPreferenceCompat
            app:key="sync"
            app:title="@string/sync_title" />

        <SwitchPreferenceCompat
            app:dependency="sync"
            app:key="attachment"
            app:summaryOff="@string/attachment_summary_off"
            app:summaryOn="@string/attachment_summary_on"
            app:title="@string/attachment_title" />

    </PreferenceCategory>
    <PreferenceCategory
        app:title="@string/help_header">
    </PreferenceCategory>

</PreferenceScreen>

Run Code Online (Sandbox Code Playgroud)

设计模式下没有文字

我的项目几乎是空的,Android Studio 是全新安装的。

android android-preferences preferencescreen

5
推荐指数
1
解决办法
152
查看次数

有没有办法将 EncryptedSharedPreference 与 PreferenceScreen 集成?

我是安卓开发的新手。目前,我想加密一个名为 Shared Preference 的自定义并与 PreferenceScreen 集成,但未能这样做。我正在使用依赖项:

  1. androidx.security:security-crypto:1.0.0-alpha02 [EncryptedSharedPreference]
  2. androidx.preference:preference:1.1.0 [PreferenceScreen]

我曾尝试研究有关这两个功能集成的相关信息,但没有找到相关信息。

从我的测试中,我有一个现有的加密共享首选项并测试了以下 API:

getPreferenceManager().setSharedPreferencesName("MyShared"); //MyShared Is custom named preference.
Run Code Online (Sandbox Code Playgroud)

但它最终以普通值保存了偏好。

我的问题:

  1. 在当前阶段是否可以将这两个功能集成在一起?
  2. PreferenceScreen 是否提供我不知道的加密功能?
  3. 如果我坚持使用 EncryptedSharedPreference,我创建一个看起来像首选项屏幕的自定义活动会更好吗?

java sharedpreferences preferencescreen android-jetpack-security

5
推荐指数
2
解决办法
889
查看次数