2017-08-26 21 views
0

ボタンが白いテキストの暗い灰色の背景を持つグローバルスタイルを作成しようとしています。テキストの色は問題ありません。私はそれを変更することができますが、何らかの理由でボタンの背景色が変わることはありません。私は間違って何をしています。ここでボタンの背景が変わらない理由

は私の色のxmlです:ここで

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <color name="colorPrimary">#bf360c</color> 
    <color name="colorPrimaryLight">#f9683a</color> 
    <color name="colorPrimaryDark">#870000</color> 
    <color name="colorPrimaryText">#000000</color> 
    <color name="colorAccent">#a4a4a4</color> 
    <color name="colorWindowBackground">#fafafa</color> 

    <color name="RED">#ff0000</color> 
    <color name="BLUE">#000fff</color> 
    <color name="GREEN">#00FF00</color> 
    <color name="YELLOW">#FFEB3B</color> 
    <color name="DARK_GREY">#494949</color> 
</resources> 

は、私のスタイルのxmlです:

<resources> 

    <!-- Base application theme. --> 
    <style name="AppTheme" parent="@style/Theme.AppCompat"> 
     <!-- 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:textColor">@color/colorPrimaryText</item> 
     <item name="android:textColorSecondary">@color/colorAccent</item> 
     <item name="android:windowBackground">@color/colorWindowBackground</item> 
     <item name="android:buttonStyle">@style/buttonColor</item> 

    </style> 

    <style name="buttonColor" parent="android:style/Widget.Button"> 
     <item name="android:textColor">@color/colorWindowBackground</item> 
     <item name="android:colorBackground">@color/DARK_GREY</item> 
    </style> 

</resources> 

そして、なぜ私の終了ボタンは、突然のすべてを縮小しましたか? enter image description here

私はこれを持っていますが、終了ボタンは縮小しましたか?あなたは、ボタンの背景を設定するにはどうすればよい

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="16dp" 
    tools:context="com.checkinsystems.ez_score.MainActivity"> 

    <Button 
     android:id="@+id/match_button" 
     android:layout_width="0dp" 
     android:layout_height="65dp" 
     android:onClick="goToMatchScreen" 
     android:text="@string/match_button" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent"/> 

    <Button 
     android:id="@+id/competitors_button" 
     android:layout_width="0dp" 
     android:layout_height="65dp" 
     android:layout_marginTop="15dp" 
     android:onClick="goToCompetitorsScreen" 
     android:text="@string/competitors_button" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/match_button"/> 

    <Button 
     android:id="@+id/scores_button" 
     android:layout_width="0dp" 
     android:layout_height="65dp" 
     android:layout_marginTop="15dp" 
     android:onClick="goToScoresScreen" 
     android:text="@string/scores_button" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/competitors_button"/> 

    <Button 
     android:id="@+id/reports_button" 
     android:layout_width="0dp" 
     android:layout_height="65dp" 
     android:layout_marginTop="15dp" 
     android:onClick="goToReportsActivity" 
     android:text="@string/reports_button" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/scores_button"/> 

    <Button 
     android:id="@+id/exit_button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/exit_button" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent"/> 

</android.support.constraint.ConstraintLayout> 

答えて

0

android:background="" 
+0

これは簡単で機能しました。 colorBackgroundは、アンドロイドの属性であると考えられます。また、私は新しいインターフェイスを投稿するつもりです。なぜ色を変えるとボタンのサイズが変わるのですか?意味がない –

+0

@ HelpMeImStupidボタンのxmlを入れて、何が起きているかを確認する必要があります。 – joao86

+0

done。どんな手掛かり?奇妙な動作です –

0

使用ボタン出口とあなた第二の問題について

<item name="colorButtonNormal">@color/yourColor</item> 

代わりの

<item name="android:colorBackground">@color/DARK_GREY</item>`. 
+0

私はそれを試しましたが、colorButtonNormalはAPI 21で、私の分は19です。joao86のように背景を変更するとうまくいきましたが、今度は終了ボタンが小さくなります –

+0

幅と高さにラップコンテンツを使用しないでください。それはボタンを小さくするでしょう。 – Abhi

0

"wrap_content" から幅とボタンの高さを変更してみてください
... 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
... 
関連する問題