Android无边框按钮
我不想成为第三个问这个问题的人,但前一个问题似乎没有完全回答。android设计指南很详细,但没有详细说明如何制作。在前面的一个答案中,有一个建议:Android无边框按钮,android,view,styles,Android,View,Styles,我不想成为第三个问这个问题的人,但前一个问题似乎没有完全回答。android设计指南很详细,但没有详细说明如何制作。在前面的一个答案中,有一个建议: style=“@android:style/Widget.Holo.Button.Borderless” 这对全息主题很有效,但我使用了很多全息。光和 style=“@android:style/Widget.Holo.Light.Button.Borderless” 似乎不存在。有没有办法在Holo.Light中为这些无边框按钮应用样式,或者更好
style=“@android:style/Widget.Holo.Button.Borderless”
这对全息主题很有效,但我使用了很多全息。光和
style=“@android:style/Widget.Holo.Light.Button.Borderless”
似乎不存在。有没有办法在Holo.Light中为这些无边框按钮应用样式,或者更好的方法是,只应用无边框标记而不指定它所属的主题,这样应用程序就可以在运行时选择合适的样式
Holo.ButtonBar似乎适合我所寻找的东西,只是它没有提供用户关于它被按下的反馈
此外,文档中是否列出了可以应用的样式及其说明?无论我在谷歌上搜索了多少,在文档中搜索,我都找不到任何东西。如果我右键单击并编辑样式,则只有一个非描述性列表
任何帮助都将不胜感激
编辑:从javram那里得到了一个完美的答案,我想为任何有兴趣添加google采用的部分边界的人添加一些XML
对于水平分隔器,这非常有效
<View
android:id="@+id/horizontal_divider_login"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="@color/holo_blue" />
这是一个垂直的:
<View
android:id="@+id/vertical_divider"
android:layout_width="1dip"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="@color/holo_blue" />
此代码将删除按钮的所有背景:
android:background="@android:color/transparent"
看看我的答案。简而言之,正确的解决方案是使用以下方法:
android:background="?android:attr/selectableItemBackground"
只需在
按钮标记中添加以下样式属性:
style="?android:attr/borderlessButtonStyle"
来源:如果有人想为不支持Holo主题的API寻找轻量级解决方案来获得无边界按钮(就像我很久以前做的那样),我会在下面发布我的解决方案:
<View
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#505154"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/btn_Reply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@android:color/transparent"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:text="@string/btnReplyText"/>
<View
android:layout_height="fill_parent"
android:layout_width="1dp"
android:background="#505154"
android:layout_marginBottom="7dp" android:layout_marginTop="7dp"/>
<Button
android:id="@+id/btn_Delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:background="@android:color/transparent"
android:text="@string/btnDeleteText" />
<View
android:layout_height="fill_parent"
android:layout_width="1dp"
android:background="#505154"
android:text="@string/btnReplyText"
android:layout_marginBottom="7dp" android:layout_marginTop="7dp" />
<Button
android:id="@+id/btn_Exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center"
android:text="@string/btnExitText"
android:paddingBottom="15dp" android:paddingTop="15dp"
android:textColor="#5c5966"
android:background="@android:color/transparent"/>
</LinearLayout>
你所要做的就是改变颜色和文字以适应你自己的背景。祝你一切顺利 冒着打败一匹死马的风险,这里有另一个(可能更好)选择。AppCompat v7定义了无边框按钮样式。如果您已经在使用AppCompat库,只需执行以下操作:
这似乎是一个非常简单的答案,只需回答三个问题,但它确实做到了。另外,对于后来看到这一点并想知道,为了获得谷歌采用的半边界,我在第一篇文章中添加了一些对我有用的代码,因为在子响应中发布代码很难阅读。我记得在我试图弄明白这一点时,我也有同样的想法。我用它作为一个超链接,这应该是一个相对简单的任务,或者我是这么想的……当按下无边框按钮时,我没有收到用户的反馈。没有亮点什么的。我错过了什么吗?@dead我不符合API 11的要求。My min设置为10。这是一个很好的答案,但请记住,该属性是在API 11中添加的。无边框按钮样式将背景设置为selectableItemBackground,并设置一些填充,仅此而已。@Xdg如果使用HolloEveywhere,它将起作用。如果使用AppCompat库,请删除“android:”前缀,它将工作:android:background=“?attr/selectableItemBackground”