【问题标题】:Rounded corners on all Buttons in Theme - how to override?主题中所有按钮的圆角 - 如何覆盖?
【发布时间】:2011-10-20 15:06:20
【问题描述】:

我一直在寻找一种简单的方法来让我的整个应用程序中的所有按钮都有圆角。

我没有成功,所以我想我会问=)

我的 AndroidManifest.xml:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/BlackTheme" android:alwaysRetainTaskState="true" android:name="MyApplication">

我的样式.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>

我的 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> 

【问题讨论】:

  • 您可以将它们全部更改为 ImageButtons 并使用 PowerPoint 中制作的圆角框的 9 补丁可绘制对象。 :)
  • 那么,你遇到了什么问题?
  • @LalitPoptani 问题是按钮没有改变,根本没有圆角。
  • @cornbreadninja 不,请不要使用 9 补丁。那是一种可怕的工作方式......应该以某种方式使用角落的半径......
  • 检查这个虽然这是editText stackoverflow.com/questions/3646415/…

标签: android button themes


【解决方案1】:

据我了解,您正在尝试将一些抽象可绘制对象(在您的情况下为Shape Drawable)指定为按钮背景,稍后将与任何其他可绘制对象集组合为按钮背景。不幸的是,这是不可能的。如果你想要一个圆角的背景,你需要提供包含圆角的drawable资源,不管它是什么类型的drawable:Shape Drawable、九个补丁等。

但是,您可以考虑继承 Button 小部件并覆盖其 draw 方法,您可以在其中随意操作按钮的外观。

【讨论】:

  • 嗯,所以将背景设置为带有圆角的可绘制对象会起作用吗?甚至可能是:stackoverflow.com/a/3646629/175830?
  • 是的,为什么不呢?使用 Shape Drawable,例如:&lt;shape android:shape="rectangle"&gt; &lt;solid android:color="#FF707070"/&gt; &lt;corners android:radius="4dp"/&gt; &lt;stroke android:width="1px" android:color="#Ffff" /&gt; &lt;/shape&gt; 并将其设置为按钮的背景。
  • 好的,只要我还能看到按下按钮的视觉效果和所有内容,这应该可以工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2018-08-18
相关资源
最近更新 更多