我试图让我的所有活动都有一个自定义主题样式,如下所示:

这个主题适用于许多设备,包括Nexus 7,三星Galaxy S4和三星Droid Charge(运行姜饼).但是,在其他设备上,例如HP Slate 7和Motorola Droid RAZR,它最终看起来像这样:

我AndroidManifest.xml的application标签中有以下内容:
android:theme="@style/AppTheme"
Run Code Online (Sandbox Code Playgroud)
主题如下res/values/styles.xml:
<style name="AppBaseTheme" parent="@android:style/Theme.Light.NoTitleBar">
</style>
<style name="AppTheme" parent="@style/AppBaseTheme">
<item name="android:windowBackground">@color/background</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我还加了styles.xml下res/values-v11.这是适用的风格:
<style name="AppBaseTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
</style>
Run Code Online (Sandbox Code Playgroud)
最后,这似乎在styles.xml下面res/values-v14:
<style name="AppBaseTheme" parent="@android:style/Theme.DeviceDefault.Light">
</style>
Run Code Online (Sandbox Code Playgroud)
我试图为每个活动定义主题并手动使用该setTheme()功能onCreate(),但没有任何效果.我还试图在每个人手动设置一个背景Activity,但这也不起作用.我该怎么做才能解决我的问题?
编辑:有趣的是设置android:background样式使其工作,但是那些不应该有背景的元素也会收到背景颜色.
android android-manifest android-layout android-activity android-styles
我正在尝试根据用户实时指定的输入为我的Android应用程序实现动态按钮膨胀.单击时,按钮将其颜色从蓝色更改为红色.
负责此的代码如下:
LayoutInflater layoutsInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.layout_for_buttons);
// Let's say that now we need only 3 buttons:
for (int i = 0; i < 3; i++) {
RelativeLayout buttonLayout = (RelativeLayout) layoutsInflater
.inflate(R.layout.button_layout, linearLayout, false);
Button button = (Button) buttonLayout.getChildAt(0);
button.setText("Button " + i);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View buttonView) {
Button button = (Button) buttonView;
GradientDrawable gradientDrawable = (GradientDrawable) button
.getBackground();
gradientDrawable.setColor(Color.RED);
gradientDrawable.invalidateSelf();
}
});
linearLayout.addView(buttonLayout);
linearLayout.invalidate();
}
Run Code Online (Sandbox Code Playgroud)
我追加按钮的布局很简单LinearLayout:
<LinearLayout …Run Code Online (Sandbox Code Playgroud)