android - 删除无边框按钮的边框

标签 android android-styles

我有这个按钮:

<Button
    android:id="@+id/btn_action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:theme="@style/AppTheme.Button.Toolbar"/>

还有这种风格:

<style name="AppTheme.Button.Toolbar" parent="Widget.AppCompat.Button.Borderless">
    <item name="colorButtonNormal">@color/main</item>
    <item name="android:textColor">@color/secondary</item>
</style>

即使样式继承自Widget.AppCompat.Button.Borderless,按钮仍然有边框。

Button 更改为 android.support.v7.widget.AppCompatButton 没有帮助。

那么如何去掉边框呢?

编辑:

设置按钮背景不是一个选项 - 这样做会丢失波纹效果的动画。

编辑2:

事情变得更加有趣。

尝试按照@cadet的建议将android:theme更改为style

当按钮以这种方式定义时:

<Button
    android:id="@+id/btn_action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:theme="@style/ToolbarButton"/>

这就是我得到的:

enter image description here

颜色适用,但有明显的边框。

如果我只是将主题更改为样式:

<Button
    android:id="@+id/btn_action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    style="@style/ToolbarButton"/>

我明白了:

enter image description here

没有边框,样式仅部分应用(文本是彩色的,按钮不是)

编辑3:

friend 们,我正在寻找一种使用样式方法获得具有波纹效果的无边框样式按钮的方法。单独修改布局文件中的每个按钮可能会起作用,但这不是重点。

最佳答案

试试这个,希望对你有帮助

<Button
    android:id="@+id/btn_photo_lib"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="startPhotoLibAction"
    android:src="@drawable/library_blau_2"
    style="?android:attr/borderlessButtonStyle"/>

android:background="@null"

关于android - 删除无边框按钮的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46447460/

相关文章:

Android Instrumentation 测试关注 : debug vs. Release模式

android - 从特定日期启动 DatePicker 对话框

Android级联布局?

android - 在主要 Activity 的选项卡顶部拉伸(stretch)的 fragment 约束布局

android - 注入(inject)类如何获得对注入(inject)器的引用?

android - 将 Facebook 插件与 Unity 一起使用时出现 ActivityNotFoundException

java - Activity 主题不变

java - 对话框 fragment 中未显示标题

android - 如何设置复选框边框颜色

Android添加css文件