2016-10-12 7 views
0

Style.xmlファイル(AppThemeは私のアプリのテーマであり、それはmateriallightdarkactionbarのテーマを継承している) アンドロイドスタジオのすべてのボタンのスタイルを変更するには?

<!-- Base application theme. --> 
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="android:colorForeground">@color/holo_orange_light</item> 
    <item name="android:buttonStyle">@style/newbuttonstyle</item> 
</style> 
<style name="newbuttonstyle" parent="@android:style/Widget.Button"> 
    <item name="android:backgroundTint">#acd9e6</item> 
</style> 

</resources> 

私は電卓を設計していますし、これはそれのためのキーパッドです.....ではなく、個別に設定しますすべてのボタンの背景色合いstyle.xmlを使用して、すべてのボタンのスタイルを変更したいのですが...できますか?この中

img

は私がのButtonStyleを使用していますが、まだ私が自分のアプリケーションのコード上で使用しています

<item name="android:buttonStyle">@style/newbuttonstyle</item> 
+3

可能な重複します(http:/を/stackoverflow.com/questions/2410836/how-do-i-apply-a-style-to-all-buttons-of-an-android-application) –

+0

これを試す:http://stackoverflow.com/questions/17192104/change-button-in-the-whole-application –

+0

あなたは、ボタン自体のスタイルを明示的に言わなければならないと言っています。 @ style/newbuttonstyle

答えて

0
<style name="newbuttonstyle" parent="@android:style/Widget.Button"> 
    <item name="android:background">#acd9e6</item> 
</style> 

動作していないし、その代わりに、一連の背景を考えるfine.i作業しますbackgroundTint。 その可能性があります。

チェックこのリンク:あなたはロリポップの下でチェックする必要がlolipop.soでtintbackgroundで ReferenceLink

とそのいくつかの問題。 style.xmlファイル内のXMLファイルで

+0

これは、各ボタンのstyle = "@ style/newbuttonstyle"を定義した場合にのみ機能しますが、 @ style/newbuttonstyle –

+0

あなたのcompilesdkのバージョンは何ですか? – dipali

+0

24私のコンパイルsdkバージョン –

1

<Button 
style="@style/MyButtonStyle" 
android:id="@+id/btnSignIn" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:text="my button"/> 

は、このコードを追加します。

<style name="ButtonStyle" parent="@android:style/Widget.Button"> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:textColor">@color/black</item> 
     <item name="android:textSize">15sp</item> 
     <item name="android:padding">10dp</item> 
     <item name="android:textStyle">bold</item> 
     <item name="android:background">@color/colorPrimary</item> 
     <item name="android:gravity">center</item> 
    </style> 

あなたの要件に応じてスタイルアイテムを変更します。

あなたは、この質問に従ってください、それはあなたのために働くことを願っていますし、あなたのスタイル部分消去することができ
+0

私は一度にすべてのボタンのスタイルを定義する方法はありませんか? –

+0

すべてのボタンにスタイルを与える最後の最良の方法。 –

+0

ちょうどあなたはすべてのボタンにstyle = "@ style/MyButtonStyle"を入れなければなりません。thats it –

関連する問題