【问题标题】:Android: Make default holo button opaqueAndroid:使默认全息按钮不透明
【发布时间】:2012-12-02 10:36:39
【问题描述】:

默认情况下,ICS 中的按钮有点透明。 我想实现该按钮保留其所有属性(形状、颜色、按下状态),但不要使其不透明。

我怎样才能做到这一点?

提前致谢!

【问题讨论】:

  • 您需要为此按钮提供自己的背景。

标签: java android android-layout button transparency


【解决方案1】:

您可以为扩展默认样式的按钮创建一个样式(如果您使用的是 Holo.Light):

<style name="GreenButton" parent="android:Widget.Holo.Button">
    <item name="android:background">#00ff00</item>
</style>

然后手动将样式应用到带有 style 属性的按钮,或者,如果您想更改所有按钮,请在应用的主题中设置 buttonStyle:

<style name="AppTheme" parent="android:Theme.Holo">
    <item name="android:buttonStyle">@style/GreenButton</item>
</style>

【讨论】:

  • 这样我可以让它变得不透明,但由于某种原因,这并不能保持全息风格。
  • @Merlin 当您使用纯全息时,请尝试从两种样式中移除光。
【解决方案2】:

您也可以在按钮下方使用纯色背景的视图。鉴于您有相对布局,这对您很有帮助。

<View
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_alignTop="@+id/button"
    android:layout_alignLeft="@id/button"
    android:layout_alignBottom="@id/button"
    android:layout_alignRight="@id/button"
    android:background="@android:color/black"
    />

【讨论】:

  • 这也是一个很好的解决方案!我认为这可能会派上用场!谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-05
  • 2015-02-05
  • 1970-01-01
  • 2012-05-24
  • 2014-02-13
  • 2021-01-31
  • 2012-10-24
相关资源
最近更新 更多