如何在 Android 中创建无边框按钮 [英] How to Create Borderless Buttons in Android

查看:40
本文介绍了如何在 Android 中创建无边框按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 设计指南说要使用无边框按钮(见图下面),但没有真正解释如何.几周前有人在这里问过同样的问题:如何创建标准的无边框按钮(就像在提到的设计指南中一样)? 并且有一个标记为the"的答案,但我仍然迷路了,我看不到添加评论的方法一个已经关闭"的问题

The Android Design Guidelines say to use borderless buttons (see picture below), but don't really explain how. Someone asked this same question a few weeks ago here: How to create standard Borderless buttons (like in the design guidline mentioned)? and there was an answer marked as "the" answer, but I am still lost and I don't see a way to add comments to a question that has been "closed"

回答者说

"查看主题属性buttonBarStyle,buttonBarButtonStyleborderlessButtonStyle"

"Look into the theme attributes buttonBarStyle, buttonBarButtonStyle, and borderlessButtonStyle"

但我仍然不知道如何实际使用这些东西.我用谷歌搜索了一下,找不到任何东西,所以我想我应该再问一次这个问题,希望有人能提供更多关于它是如何工作的细节.

but I still can't figure out how to actually use those things. I Googled around a bit and couldn't find anything so I figured I'd just ask the question again, and hopefully someone can provide a little more detail on how this works.

推荐答案

几周前,当我在这里看到有关使用透明背景的答案时,我以为我已经解决了这个问题,但它不够好,因为它防止按钮在按下时突出显示.

I thought I had this solved when I looked here a few weeks ago and noticed the answer about using a transparent background but it isn't quite good enough because it prevents the button from being highlighted when pressed.

此外,将样式设置为 Widget.Holo.Button.Borderless 也不合适,因为它会使按钮边界变大.

Also, setting the style to Widget.Holo.Button.Borderless isn't appropriate because it makes the button boundaries to big.

为了一劳永逸地解决这个问题,我检查了标准日历应用程序的 android 源代码,发现它使用以下内容:

To figure this out once and for all, I check the android source code for the standard Calendar app and found that it uses the following:

android:background="?android:attr/selectableItemBackground"

这样做可以确保按钮无边框并且大小正确.

Doing it this way ensures the button is borderless and the correct size.

这篇关于如何在 Android 中创建无边框按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆