我想让我的应用程序具有多种样式。
该样式更改按钮样式、文本视图颜色和布局背景颜色。
我在 xml 文件中有我的按钮样式。
这是我的代码:style.xml (v21)
<style name="ThemeIndigo" parent="@android:style/Theme.Material.NoActionBar">
<item name="android:colorPrimary">@color/indigo</item>
<item name="android:colorPrimaryDark">@color/indigo</item>
<item name="android:navigationBarColor">@color/indigo_dark</item>
<item name="android:buttonStyle">@drawable/indigo_button</item>
<item name="android:background">@drawable/indigo_button</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这会更改此布局上所有内容的背景颜色。
如何让我的样式只改变按钮的颜色?
请帮忙。谢谢。
(抱歉英语不好;)
int sch = 1;
if (sch == 1){
Log.d("check", "1");
}
if (sch == 2){
Log.d("check", "2");
}
else {
Log.d("check", "error!");
}
Run Code Online (Sandbox Code Playgroud)
这是一个非常简单的陈述.
我在我的android java代码中使用完全相同的语句,
它check: 1在logcat中显示为假设.
当我得到我正在使用的真实代码时,
int sch = 1;
if (sch == 1){
activity.getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.white));
if (android.os.Build.VERSION.SDK_INT >= 21) {
activity.getWindow().setNavigationBarColor(getResources().getColor(R.color.white));
activity.getWindow().setStatusBarColor(getResources().getColor(R.color.red));}
Log.d("check", "1");
}
if (sch == 2){
activity.getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.white));
if (android.os.Build.VERSION.SDK_INT >= 21) {
activity.getWindow().setNavigationBarColor(getResources().getColor(R.color.white));
activity.getWindow().setStatusBarColor(getResources().getColor(R.color.green));}
Log.d("check", "2");
}
else {
activity.getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.white));
if (android.os.Build.VERSION.SDK_INT >= 21) {
activity.getWindow().setNavigationBarColor(getResources().getColor(R.color.white));
activity.getWindow().setStatusBarColor(getResources().getColor(R.color.white));}
Log.d("check", "error");
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,它应显示 …