Android普通按钮变透明

标签 android android-layout

我有一个 RelativeLayout,背景设置为 android:background="@drawable/background"

在我的 RelativeLayout 中,我有一个标准按钮,但是当我在运行 3.1 或更高版本的设备上运行该应用程序时,该按钮显示为透明。

我曾尝试将 android:alpha 设置为 1,但没有成功。

我知道我可以使用选择器和形状制作自定义背景,但必须有另一种方法。

还有其他人遇到过这个问题吗?

最佳答案

您需要将类似的内容添加到您的 style.xml

应用主题

<style name="ApplicationStyle" parent="android:Theme">
  <item name="android:buttonStyle">@style/MyButtons</item>
</style>

按钮样式

<style name="MyButtons" parent="@android:style/Widget.Button">
    <item name="android:textSize">16sp</item>
    <item name="android:background">#000000</item>
</style>

确保您也在 list 中正确设置了主题

<application
    android:allowBackup="true"
    android:icon="@drawable/app_icon"
    android:label="@string/app_name"
    android:theme="@style/Theme.ApplicationStyle" >

关于Android普通按钮变透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15501214/

相关文章:

android - 具有 GridLayoutManager 的 RecyclerView 和具有不同 viewHolder 的第一个元素

Android 文件复制导致 java.io.IOException : File descriptor closed

android - 设置权重后如何获取 MeasuredWidth()

android - 类似 evernote 的操作栏 - 向上按钮和选项卡在顶部的一行中,菜单操作在底部

java - 导航 View 点击事件

java - 使用相对布局和按钮将一个 videoView 覆盖在另一个 videoView 上

java - 在任务 'classpath' 上找不到属性 ':app:transformJackWithJackForDebug'

android - Simperium 中用于添加数据加密的插入点在哪里?

java.io.IOException : HTTP request failed, HTTP 状态:500 在 android 中使用 WCF for android

android - 导航列表抽屉不是 ListView?