为什么getApplicationContext()。setTheme()在活动不能正常工作? [英] Why getApplicationContext().setTheme() in a Activity does not work?

查看:809
本文介绍了为什么getApplicationContext()。setTheme()在活动不能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前也很难召集到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);
}
 

}

解决方案

我有同样的问题之前,并没有找到一个方法来解决这个问题

。只有上帝知道为什么,但我还看过Android框架工程师(我相信这是戴安娜Hackborn)说,设定主题,像这样的鼓励。

设置主题,为您在清单中的活动,而是和它的工作。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆