我的 SharedPreferences 仅显示不可见文本

发布于 2024-10-31 04:51:28 字数 2304 浏览 4 评论 0原文

我按照“书本”的说明在我的应用程序中生成了一个 SharedPreferences 屏幕。没什么特别的。但我在屏幕上只能看到不可见的偏好设置(模拟器和手机)。

这是屏幕截图(抱歉,这是链接。我不允许发布图片): 打印属性屏幕

请注意,我尝试使用默认主题和 Light -

这里 没有标题代码: XML/preferences.xml:

    <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http: //schemas. android.com/apk/res/android">
<PreferenceCategory
            android:title="@string/menukad">
    <CheckBoxPreference
        android:key="menukad12"
        android:defaultValue="false"
        android:title="Nikud in the Text?"
        android:summary="@string/menukad" />

    <CheckBoxPreference
                        android:title="Checkbox Preference"
                        android:defaultValue="false"
                        android:summary="This preference can be true or false"
                        android:key="checkboxPref" />
</PreferenceCategory>       

</PreferenceScreen>

myPreferences.java

    package com.android.orvishua.mishneTorah;


import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.KeyEvent;

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

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            chapterSave.setReLoad(true);
        }
        return super.onKeyDown(keyCode, event);
    }

}

读取首选项:

public SharedPreferences myprefs;
public boolean menukad; 


         myprefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()) ;
        menukad = myprefs.getBoolean("menukad12", false);

Manifest(所有其他活动均使用默认样式。没有更改):

<activity android:name=".myPreferences" android:label="@string/app_name" />

或者

<activity android:name=".myPreferences" android:theme="@android:style/Theme_Light_NoTitleBar" android:label="@string/app_name" />

有人可以帮助我吗???

I've generated a SharedPreferences screen in my application following instructions "by the book". Nothing special. But I get only invisible preferences on screen (both simulator and phone).

Here's the screenshots (sorry, it's link. i'm not allowed to post image):
Print Screens of Properties

Notice that I tried with default Theme and also Light - No Title

Here's the code:
XML/preferences.xml:

    <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http: //schemas. android.com/apk/res/android">
<PreferenceCategory
            android:title="@string/menukad">
    <CheckBoxPreference
        android:key="menukad12"
        android:defaultValue="false"
        android:title="Nikud in the Text?"
        android:summary="@string/menukad" />

    <CheckBoxPreference
                        android:title="Checkbox Preference"
                        android:defaultValue="false"
                        android:summary="This preference can be true or false"
                        android:key="checkboxPref" />
</PreferenceCategory>       

</PreferenceScreen>

myPreferences.java

    package com.android.orvishua.mishneTorah;


import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.KeyEvent;

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

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            chapterSave.setReLoad(true);
        }
        return super.onKeyDown(keyCode, event);
    }

}

Reading preferences:

public SharedPreferences myprefs;
public boolean menukad; 


         myprefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()) ;
        menukad = myprefs.getBoolean("menukad12", false);

Manifest (all other Activities are with the default style. no changes):

<activity android:name=".myPreferences" android:label="@string/app_name" />

or

<activity android:name=".myPreferences" android:theme="@android:style/Theme_Light_NoTitleBar" android:label="@string/app_name" />

Can someone help me???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-11-07 04:51:28

尝试在 styles.xml 中创建自己的主题(如果没有,请在值文件夹中创建)

例如,

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourStyle" parent="android:Theme.Light">
    <item name="android:listViewStyle">@style/Widget.ListView</item>
    <item name="android:textColor">@color/your_color</item>
    <item name="android:windowNoTitle">true</item>
</style>

<style name="Widget" parent="android:Widget">
</style>

<style name="Widget.ListView">
    <item name="android:background">@color/white</item>
    <item name="android:divider">@color/gray_division</item>
    <item name="android:dividerHeight">2dip</item>       
</style>
</resources>

我希望这会有所帮助

Try creating your own theme in your styles.xml (if you dont have one, create it in the values folder)

For example

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourStyle" parent="android:Theme.Light">
    <item name="android:listViewStyle">@style/Widget.ListView</item>
    <item name="android:textColor">@color/your_color</item>
    <item name="android:windowNoTitle">true</item>
</style>

<style name="Widget" parent="android:Widget">
</style>

<style name="Widget.ListView">
    <item name="android:background">@color/white</item>
    <item name="android:divider">@color/gray_division</item>
    <item name="android:dividerHeight">2dip</item>       
</style>
</resources>

I hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文