为什么getApplicationContext()。setTheme()在活动不能正常工作? [英] Why getApplicationContext().setTheme() in a Activity does not work?
问题描述
我目前也很难召集到getApplicationContext()。setTheme()在活动中,我只是想应用主题资源的应用范围,而不是在code风格的活动范围,但麻烦是,这并不在所有的工作,任何人可以解释这一点,非常感谢!
他是code骨架:
公共类启动延伸活动{
@覆盖
公共无效的onCreate(包savedInstanceState){
/ *
* setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
* //的作品!
* /
this.getApplicationContext()。setTheme(
android.R.style.Theme_Black_NoTitleBar_Fullscreen);
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
}
}
解决方案我有同样的问题之前,并没有找到一个方法来解决这个问题
设置主题,为您在清单中的活动,而是和它的工作。
i am currently have a hard time for calling to getApplicationContext().setTheme() in a activity,i just want to apply a theme resource in a application scope instead of activity scope in code style,but the trouble is that this does not work at all,can anybody explain to this,thanks a lot!
He is the code skeleton:
public class StartUp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
/*
* setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
* //that works!
*/
this.getApplicationContext().setTheme(
android.R.style.Theme_Black_NoTitleBar_Fullscreen);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
I had the same problem before and didn't find a way to fix this. Only god knows why, but I've even seen Android framework engineers (I believe it was Dianne Hackborn) say that setting themes like this is discouraged.
Set the theme for your Activity in the Manifest instead, and it will work.
这篇关于为什么getApplicationContext()。setTheme()在活动不能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!