[英]Android - style.xml takes no effect
I found topic with instruction - how to set theme for whole application: 我发现了带有说明的主题-如何为整个应用程序设置主题:
Setting global styles for Views in Android 在Android中为视图设置全局样式
It does not work for me at all. 它根本不适合我。 Here's my code: 这是我的代码:
style.xml: style.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--1-->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:radioButtonStyle">@style/TBRadioButtonStyle</item>
</style>
<style name="TBRadioButtonStyle" parent="android:Widget.CompoundButton.RadioButton">
<item name="android:textColor">#F00</item>
<item name="android:textStyle">bold</item>
<item name="android:background">@drawable/state_color_selector</item>
</style>
</resources>
state_color_selector.xml: state_color_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<color android:color="#F00" />
</item>
<item android:state_checked="false">
<color android:color="#0F0" />
</item>
</selector>
AndroidManifest.xml: AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.app" >
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".controller.ApplicationController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".view.DrawersWidget"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
.java file with RadioButton creation: 带有RadioButton创建的.java文件:
RadioButton newButton = new RadioButton(ApplicationController.INSTANCE.getApplicationContext());
//...
newButton.setLayoutParams(new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
newButton.setButtonDrawable(new BitmapDrawable(ApplicationController.INSTANCE.getResources(), filteredBitmap));
newButton.setText(someText);
创建RadioButton时,请使用Activity的上下文,而不是ApplicationContext。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.