0

ボタンの主な色をcolorPrimaryに変更するために、このコードを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> 
</style> 

<style name="AppTheme.Button" parent="Base.Widget.AppCompat.Button"> 
    <item name="colorButtonNormal">@color/colorPrimary</item> 
</style> 

</resources> 

は、その後、私は私はあなたがripple_effect xmlファイルを作成し、ボタンの背景としてそれを使用する必要があり、別のスタックの記事で読んで以来、波及効果と組み合わせてみました。次に、ボタンのスタイルをstyle.xmlに詳述されているカスタムスタイルに設定します。私は私が間違っているのは何エディタ

enter image description here

のボタンにリンクされている方法

。リップル効果をボタンに加え、色を追加する方が簡単です。私はスタックのオーバーフローポストでこれを修正しようとしていますが、すべての解決策は異なっています。私は、API 23

答えて

0

あなたはsetColorFilterを使用することができます()の午前:

ThemeOverlay Sを使用して達成することができる
btn.getBackground().setColorFilter(color, PorterDuff.Mode.MULTIPLY); 
0

<style name="GreenButtonTheme" parent="ThemeOverlay.AppCompat.Light"> 
    <item name="colorButtonNormal">@color/green</item> 
</style> 

そして、あなたのxmlで:

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    android:theme="@style/GreenButtonTheme" /> 

その後、あなたは、この出力が得られます:res/values/themes.xmlでこれを持っ

enter image description here

参照this article多くのため詳細。

関連する問題