首选项屏幕编码问题

发布于 2024-11-28 17:28:41 字数 2546 浏览 3 评论 0原文

我对这段代码有一个大问题:

public class Preferences extends PreferenceActivity {

private LinearLayout rootView;


private LinearLayout titleView;

private ListView preferenceView;

private TextView textView;



@Override

protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

    rootView = new LinearLayout(this);
    rootView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    rootView.setOrientation(LinearLayout.VERTICAL);

    textView = new TextView(this);
    textView.setText(R.string.tx_einstellungen);
    textView.setTextColor(Color.WHITE);
    textView.setTextSize(20);

    titleView = new LinearLayout(this);
    titleView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 45));
    titleView.setBackgroundResource(R.color.background);
    titleView.addView(textView);
    titleView.setGravity(Gravity.CENTER);

    preferenceView = new ListView(this);
    preferenceView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    preferenceView.setId(android.R.id.list);

    PreferenceScreen screen = createPreferenceHierarchy();
    screen.bind(preferenceView);
    preferenceView.setAdapter(screen.getRootAdapter());

    rootView.addView(titleView);
    rootView.addView(preferenceView);


    this.setContentView(rootView);

    setPreferenceScreen(screen);

}


private PreferenceScreen createPreferenceHierarchy() {

    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
    PreferenceScreen lang_screen = getPreferenceManager().createPreferenceScreen(this);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    // Screen preference

    lang_screen.setKey("language_pref");
    lang_screen.setTitle("Sprache");
    lang_screen.bind(preferenceView);
    root.addPreference(lang_screen);

    // Example of next screen toggle preference
    CheckBoxPreference nextScreenCheckBoxPref = new CheckBoxPreference(this);
    nextScreenCheckBoxPref.setKey("next_screen_toggle_preference");
    nextScreenCheckBoxPref.setTitle("");
    nextScreenCheckBoxPref.setSummary("");
    lang_screen.addPreference(nextScreenCheckBoxPref);


    return root;

}

第一个 PreferenceScreen 是一个漂亮的白色屏幕,顶部有一条蓝线,在该行中我们有白色的英文“Preferences”文本“Einstellungen”。

然而,当我点击“Sprache”时,下一个预置屏幕是黑色的,并且有一个 android 标题栏......我想创建更多“预置屏幕下”,它们都必须是白色的,顶部有这些蓝线。

请帮助

谢谢亚历克斯

i have a big Problem with this Code:

public class Preferences extends PreferenceActivity {

private LinearLayout rootView;


private LinearLayout titleView;

private ListView preferenceView;

private TextView textView;



@Override

protected void onCreate(Bundle savedInstanceState) {

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

    rootView = new LinearLayout(this);
    rootView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    rootView.setOrientation(LinearLayout.VERTICAL);

    textView = new TextView(this);
    textView.setText(R.string.tx_einstellungen);
    textView.setTextColor(Color.WHITE);
    textView.setTextSize(20);

    titleView = new LinearLayout(this);
    titleView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 45));
    titleView.setBackgroundResource(R.color.background);
    titleView.addView(textView);
    titleView.setGravity(Gravity.CENTER);

    preferenceView = new ListView(this);
    preferenceView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    preferenceView.setId(android.R.id.list);

    PreferenceScreen screen = createPreferenceHierarchy();
    screen.bind(preferenceView);
    preferenceView.setAdapter(screen.getRootAdapter());

    rootView.addView(titleView);
    rootView.addView(preferenceView);


    this.setContentView(rootView);

    setPreferenceScreen(screen);

}


private PreferenceScreen createPreferenceHierarchy() {

    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
    PreferenceScreen lang_screen = getPreferenceManager().createPreferenceScreen(this);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    // Screen preference

    lang_screen.setKey("language_pref");
    lang_screen.setTitle("Sprache");
    lang_screen.bind(preferenceView);
    root.addPreference(lang_screen);

    // Example of next screen toggle preference
    CheckBoxPreference nextScreenCheckBoxPref = new CheckBoxPreference(this);
    nextScreenCheckBoxPref.setKey("next_screen_toggle_preference");
    nextScreenCheckBoxPref.setTitle("");
    nextScreenCheckBoxPref.setSummary("");
    lang_screen.addPreference(nextScreenCheckBoxPref);


    return root;

}

The First PreferenceScreen is a nice white screen with a blue line on the top and in the line we have the Text "Einstellungen" in english "Preferences" in color white.

However when i click on "Sprache" the next prefcreen is black and there is an android Titlebar.... i want to create more "under-prefscreens" and they all have to be white with these blue line on the top.

PLEASE HELP

Thankx Alex

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

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

发布评论

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

评论(1

℉服软 2024-12-05 17:28:41

这是 Android 2.1u1 中的一个已知错误。

如果您使用多级首选项屏幕,浅色主题不会传播到下一级屏幕。对于更高的 SDK 2.2 及更高版本,它工作得很好。某些设备上也存在此问题。不幸的是,除了将主题保留为黑暗之外,还没有解决方案。

This is a known bug in Android 2.1u1.

If you use multi-level preference screen the Light theme is not propogated to next level screens. For higher SDK 2.2 and above it works perfectly fine. The issue is also on some devices. Unfortunately no solution yet for this apart from leaving the theme as dark.

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