Android 如何为代码中生成的布局设置自定义主题?(查看组)
对于我的主要活动,以下代码将主题设置为我的自定义主题:Android 如何为代码中生成的布局设置自定义主题?(查看组),android,Android,对于我的主要活动,以下代码将主题设置为我的自定义主题: setTheme(R.style.Custom); 但我从中得到的布局是什么呢: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ViewGroup layout = getLayout(getIntent().getStringExtra("key1")); if (l
setTheme(R.style.Custom);
但我从中得到的布局是什么呢:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewGroup layout = getLayout(getIntent().getStringExtra("key1"));
if (layout == null) return;
layout.addView(new ProgressBar(this));
layout.addView(new RadioButton(this));
layout.addView(new RatingBar(this));
layout.addView(new CheckBox(this));
layout.addView(new Switch(this));
layout.addView(new SeekBar(this));
layout.setBackgroundColor(Color.parseColor("#3333ff"));
setContentView(layout); }
我想更改视图组布局的主题,我尝试了
layout.setTheme(R.style.Custom); but it didn't work, what's the correct function to do this
这是我的主题代码:(有可能改变星星的颜色吗
等在这里吗?)
#99ff99
#009933
#f542e3
视图组没有“主题”或类似属性。
布局仅用于定位小部件,仅此而已
因此,您应该在onCreate()
中的所有操作之前调用setTheme()
,如下所示:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Custom);
}
或者,通过向每个构造函数传递属性,可以为每个小部件(ProgressBar、RadioButton等)设置自定义样式
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Custom);
}