[英]Rounded corners on all Buttons in Theme - how to override?
I have been looking around for an easy way to make all buttons in my entire app have rounded corners. 我一直在寻找一种简单的方法,让我的整个应用程序中的所有按钮都有圆角。
I haven't succeeded, so I thought I'd ask =) 我没有成功,所以我想我会问=)
My AndroidManifest.xml: 我的AndroidManifest.xml:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/BlackTheme" android:alwaysRetainTaskState="true" android:name="MyApplication">
My styles.xml: 我的styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ButtonHeader" parent="@android:style/Widget.Button">
<item name="android:textSize">18dip</item>
<item name="android:minWidth">70dip</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">30dip</item>
</style>
<style name="JobViewHeader" parent="@android:style/TextAppearance.Small">
<item name="android:textStyle">bold</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="BlackTheme" parent="@android:style/Theme.Black">
<item name="android:button">@drawable/button_rounded</item>
</style>
<style name="DialogTheme" parent="@android:style/Theme.Dialog">
</style>
</resources>
My button_rounded.xml (in drawables): 我的button_rounded.xml(在drawables中):
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp" />
</shape>
As I understand, you are trying to specify some abstract drawable ( Shape Drawable in your case) as a button background, which will be combined later with any other drawable set as a button background. 据我所知,你试图指定一些抽象的drawable(在你的情况下为Shape Drawable )作为按钮背景,稍后将与任何其他可绘制的组合作为按钮背景。 Unfortunately, this is impossible.
不幸的是,这是不可能的。 If you want a background with rounded corners, you need to provide drawable resource which does contain rounded corners, no matter what type of drawable it is: Shape Drawable, nine-patch, etc.
如果你想要一个带圆角的背景,你需要提供包含圆角的可绘制资源,无论它是什么类型的可绘制:Shape Drawable,九补丁等。
However you may consider subclassing the Button
widget and overriding its draw
method, where you can manipulate button's look as you wish. 但是,您可以考虑继承
Button
小部件并覆盖其draw
方法,您可以根据需要操作按钮的外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.