Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 主题改变并不意味着';t工作在<;应该是4.0_Android_Android Layout_Styles_Themes_Android Theme - Fatal编程技术网

Android 主题改变并不意味着';t工作在<;应该是4.0

Android 主题改变并不意味着';t工作在<;应该是4.0,android,android-layout,styles,themes,android-theme,Android,Android Layout,Styles,Themes,Android Theme,我在以编程方式设置“主题切换器”时遇到一些困难。 我想从应用程序切换主题(在白色(Theme.Light.NoTitleBar)和黑色(Theme.Black.NoTitleBar)之间),我要做的是: 我设置了一个SharedReference: final String PREFS_NAME = "MyPrefsFile"; final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); fina

我在以编程方式设置“主题切换器”时遇到一些困难。 我想从应用程序切换主题(在白色(Theme.Light.NoTitleBar)和黑色(Theme.Black.NoTitleBar)之间),我要做的是: 我设置了一个SharedReference:

final String PREFS_NAME = "MyPrefsFile";
    final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    final SharedPreferences.Editor editor = settings.edit();
然后我有两个按钮来切换主题(第二个几乎相同)

在乞讨的每一个活动中,我都会检查共享参考

boolean theme = settings.getBoolean("Theme", false);
    if(theme){
        this.setTheme(R.style.Theme_NoBarBlack);
    } else{
        this.setTheme(R.style.Theme_NoBar);
    }

    setContentView(R.layout.aplikacja);
我在文件夹值的file styles.xml中定义主题:

<resources>
<style name="Theme.NoBar" parent="@android:style/Theme.Light.NoTitleBar" />
<style name="Theme.NoBarBlack" parent="@android:style/Theme.NoTitleBar" />
是否在设置主题之前

因此,它应该是:

public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_NoBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lista);
}

抱歉,伙计们把问题无中生有,但当它在>3.0上工作时,我感到困惑。花半天的时间在上面,但要工作。:)

您的style.xml中有一个错误: 对于
Theme.NoBarBlack
,您将父级设置为
@android:style/Theme.NoActionBar
,但它不存在


我想你是说android:style:Theme.NoTitleBar

谢谢,但我在尝试更改主题等时犯了一个错误,然后忘了将其更改回来并复制粘贴到这里。所以一定是其他原因导致了这种奇怪的行为。很好的猜测,但Theme.NoTitleBar在该API级别上不存在。它必须是黑色的。NoTitleBar@StephanBranczyk说明
Theme.NoTitleBar
从API级别1开始就存在。你完全正确。文件中的表格把我弄糊涂了。
<resources>
<style name="Theme.NoBar" parent="@android:style/Theme.Holo.Light.NoActionBar" />
<style name="Theme.NoBarBlack" parent="@android:style/Theme.Holo.NoActionBar" />
<resources>
<style name="Theme.NoBar" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar" />
<style name="Theme.NoBarBlack" parent="@android:style/Theme.DeviceDefault.NoActionBar" />
    <application
...
        android:theme="@style/Theme.NoBar" >
super.onCreate(savedInstanceState);
public void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_NoBar);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lista);
}