[英]Cannot set button background color using styles.xml
This looks easy enough but i don't know why i'm not able to do this. 这看起来很容易,但是我不知道为什么我不能做到这一点。 This is how i want to style my button:
这就是我要为按钮设置样式的方式:
Resource file 资源文件
<Button
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:id="@+id/buttonLogin"
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ButtonTheme"/>
Styles.xml 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.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="EditTextTheme">
<item name="colorControlActivated">@color/colorPrimaryDark</item>
</style>
<style name="ButtonTheme">
<item name="android:background">@color/colorPrimary</item>
<item name="android:textColor">@color/colorWhite</item>
</style>
</resources>
But somehow the background color is still default which is grey although the text has already change color to white. 但是尽管文本已经将颜色更改为白色,但是背景颜色仍然是默认的灰色。 Why did this happen?
为什么会这样呢? And how i can overcome this?
而我该如何克服呢? Thank you in advance.
先感谢您。
Instead of 代替
android:theme="@style/ButtonTheme"
Do 做
style="@style/ButtonTheme"
on your <Button
> 在您的
<Button
>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.