我无法在styles.xml中为我的Android应用中的复选框和单选按钮制作工作样式。 复选框和单选按钮的属性仅在我直接在activity_main.xml文件中添加时才有效,如果我将它们定义为样式则不行。 你可以帮我解决这个问题吗? 非常感谢你
这里是我所说的文件:
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.marconota.soccerquiz.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"
android:scaleType="centerCrop"
android:src="@drawable/soccer_field" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<LinearLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/padding"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:paddingTop="@dimen/padding">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/paddingbottomsubtitle"
android:text="@string/test_your_soccer_knowledge"
android:textAppearance="@style/subtitle" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/which_team_did_win_2014_world_cup"
android:textAppearance="@style/questions" />
<!-- START*** CardView Container *** -->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#80d1d1d1"
card_view:cardCornerRadius="@dimen/cardcornerradius"
card_view:cardElevation="@dimen/cardelevation"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="@dimen/cardcontentpadding">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="@dimen/padding">
<RadioGroup
android:id="@+id/radiogroup_question1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/italy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/italy_item_question1"
android:textColor="@android:color/white" />
<RadioButton
android:id="@+id/brazil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/brazil_question1"
android:textColor="@android:color/white" />
<RadioButton
android:id="@+id/germany"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:buttonTint="@android:color/white"
android:text="@string/germany"
android:textColor="@android:color/white" />
</RadioGroup>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/brazil2014_def" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<!-- END*** CardView Container *** -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/who_did_win_more_golden_ball_awards"
android:textAppearance="@style/questions" />
<!-- START*** CardView Container *** -->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#80d1d1d1"
card_view:cardCornerRadius="@dimen/cardcornerradius"
card_view:cardElevation="@dimen/cardelevation"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="@dimen/cardcontentpadding">
<EditText
android:id="@+id/question2_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/please_insert_player_surname_here"
android:textAppearance="@style/edit_text"
/>
</android.support.v7.widget.CardView>
<!-- END*** CardView Container *** -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/who_did_score_more_goals_in_mexico_86"
android:textAppearance="@style/questions" />
<!-- START*** CardView Container *** -->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#80d1d1d1"
card_view:cardCornerRadius="@dimen/cardcornerradius"
card_view:cardElevation="@dimen/cardelevation"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="@dimen/cardcontentpadding">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="@dimen/padding">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/lineker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/lineker"
android:textColor="@android:color/white"/>
<RadioButton
android:id="@+id/rivera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/rivera"
android:textColor="@android:color/white" />
<RadioButton
android:id="@+id/voeller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin"
android:buttonTint="@android:color/white"
android:text="@string/voeller"
android:textColor="@android:color/white" />
</RadioGroup>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/mexico86logo_def" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<!-- END*** CardView Container *** -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin"
android:text="@string/which_team_did_win_more_world_cups"
android:textAppearance="@style/questions" />
<!-- START*** CardView Container *** -->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#80d1d1d1"
card_view:cardCornerRadius="@dimen/cardcornerradius"
card_view:cardElevation="@dimen/cardelevation"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="@dimen/cardcontentpadding">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="@dimen/padding">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/italy_question4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/italy_question4"
android:textColor="@android:color/white" />
<RadioButton
android:id="@+id/brazil_question4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/brazil_question4"
android:textColor="@android:color/white" />
<RadioButton
android:id="@+id/holland"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin"
android:buttonTint="@android:color/white"
android:text="@string/holland"
android:textColor="@android:color/white" />
</RadioGroup>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/wold_cup_def" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<!-- END*** CardView Container *** -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin"
android:text="@string/who_did_belong_italian_team_in_italy_90"
android:textAppearance="@style/questions" />
<!-- START*** CardView Container *** -->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#80d1d1d1"
card_view:cardCornerRadius="@dimen/cardcontentpadding"
card_view:cardElevation="@dimen/cardelevation"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="@dimen/cardcontentpadding">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="@dimen/padding">
<CheckBox
android:id="@+id/schillaci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/schillaci"
android:textColor="@android:color/white" />
<CheckBox
android:id="@+id/casiraghi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/schillaci"
android:buttonTint="@android:color/white"
android:text="@string/casiraghi"
android:textColor="@android:color/white" />
<CheckBox
android:id="@+id/dossena"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/casiraghi"
android:layout_marginBottom="@dimen/margin"
android:buttonTint="@android:color/white"
android:text="@string/dossena"
android:textColor="@android:color/white" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/italy90_italy_team_def" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<!-- END*** CardView Container *** -->
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/who_did_win_his_fourth_golden_ball_in_2016"
android:textAppearance="@style/questions" />
<!-- START*** CardView Container *** -->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="#80d1d1d1"
card_view:cardCornerRadius="@dimen/cardcornerradius"
card_view:cardElevation="@dimen/cardelevation"
card_view:cardPreventCornerOverlap="true"
card_view:cardUseCompatPadding="true"
card_view:contentPadding="@dimen/cardcontentpadding">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="@dimen/padding">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/cristiano_ronaldo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/cristiano_ronaldo"
android:textColor="@android:color/white" />
<RadioButton
android:id="@+id/benzema"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/benzema"
android:textColor="@android:color/white" />
<RadioButton
android:id="@+id/ibrahimovic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@android:color/white"
android:text="@string/ibrahimovic"
android:textColor="@android:color/white" />
</RadioGroup>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/golden_ball_def" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<!-- END*** CardView Container *** -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginTop="16dp"
android:onClick="displayScore"
android:src="@drawable/ok"
app:borderWidth="0dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorHint">@color/textColorHint</item>
<item name="android:textColorPrimary">@color/textColorPrimary</item>
</style>
<!-- Style for questions-->
<style name="questions">
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/textColorQuestions</item>
<item name="android:textSize">@dimen/textsizequestions</item>
<item name="android:textAllCaps">false</item>
</style>
<!-- Style for subtitle -->
<style name="subtitle">
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/textColorSubtitle</item>
<item name="android:textSize">@dimen/textsizesubtitle</item>
<item name="android:textAllCaps">false</item>
</style>
<!-- Style for edit text -->
<style name="edit_text">
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/textColorEditText</item>
<item name="android:textSize">@dimen/textsizeedittext</item>
<item name="android:textAllCaps">false</item>
</style>
<!-- Style for items -->
<style name="items">
<item name="android:textColor">@android:color/white</item>
<item name="android:textAllCaps">false</item>
</style>
</resources>
答案 0 :(得分:0)
在您想要包含样式影片的视图中,请使用:
style="@style/your_style"
答案 1 :(得分:0)
这可以给你一个想法:
<style name="myTheme" parent="@android:Theme.Holo">
<!-- override default check box style with custom checkBox -->
<item name="android:checkboxStyle">@style/CustomCheckBox</item>
<item name="android:radioButtonStyle">@style/CustomRadioButton</item>
</style>
<style name="CustomCheckBox"
parent="@android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">@drawable/foo</item>
<item name="android:textColor">@android:color/holo_purple</item>
</style>
<!-- custom style -->
<style name="CustomRadioButton"
parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:button">@drawable/foo</item>
</style>