2016-05-02 6 views
1

を事前に正しく設定されていないアンドロイド:カスタムボタンの背景色は、私は標準のボタンを使用するとロリポップ

<Button 
    android:id="@+id/btnLogin" 
    style="@style/LoginButtonsStyle" 
    android:text="@string/login.anmelden" 
    android:theme="@style/CrGreenButton"/> 

スタイル:

<style name="LoginButtonsStyle"> 
    <item name="android:layout_width">match_parent</item> 
    <item name="android:layout_height">@dimen/login_btn_height</item> 
    <item name="android:textAllCaps">false</item> 
    <item name="android:textColor">@color/white</item> 
    <item name="android:layout_marginBottom">@dimen/login_buttons_bottom_margin</item> 
</style> 

テーマ:

<style name="CrGreenButton"> 
    <item name="colorButtonNormal">@color/CrGreen</item> 
    <item name="android:colorBackground">@color/CrGreen</item> 
    <item name="android:background">@color/CrGreen</item> 
</style> 

すべてが正常に動作し、背景色は各APIレベルで設定されます。16+

しかし、私は(カスタムフォントのために必要なkotlinで書かれた、)私のカスタムボタンを使用

open class CheckrobinButton : Button { 

val fontPath = "fonts/CoreSansG55.otf" 

constructor(context: Context) : super(context) { 
    init() 
} 

constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) { 
    init() 
} 

constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super(context, attributeSet, defStyleAttr) { 
    init() 
} 

constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes){ 
    init() 
} 

private fun init() { 
    typeface = Typeface.createFromAsset(context.assets, fontPath) 
} 

} 

背景色のみをAPI21 +(ロリポップ)デバイスに設定されています。プリロリポップデバイスでは、ボタンは標準のグレー色のままです。

なぜですか?

+0

ボタンに使用しているスタイルとテーマのコードを投稿できますか? – Bob

+0

テーマとスタイルが追加されました! – lukle

+0

テーマに設定する代わりに、属性android:backgroundをButtonに直接設定することができます。 – Bob

答えて

関連する問題