我想创建自定义按钮,我需要它是圆形.如何创建圆形按钮?我不认为使用draw9patch是可能的.
另外我不知道如何制作自定义按钮!
你有什么建议吗?
我有一个按钮,如下所示.当我想禁用它时my_btn.setEnabled(false),我会使用它,但我也想将它变灰.我怎样才能做到这一点?
谢谢
<Button android:id="@+id/buy_btn" style="@style/srp_button" />
Run Code Online (Sandbox Code Playgroud)
风格/ srp_button
<style name="srp_button" parent="@android:style/Widget.Button">
<item name="android:background">@drawable/btn_default</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">14sp</item>
<item name="android:typeface">serif</item>
<item name="android:paddingLeft">30dp</item>
<item name="android:paddingRight">30dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
绘制/ btn_default.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/pink" />
<corners android:radius="6dp" />
</shape>
Run Code Online (Sandbox Code Playgroud) 如何实施谷歌材料设计指南中描述的"凸起按钮"和"平面按钮"?
凸起的按钮为大多数平面布局增加了尺寸.他们强调繁忙或宽阔空间的功能.

使用工具栏和对话框的平面按钮可避免过度分层.

资料来源:http://www.google.com/design/spec/components/buttons.html
我已经看到标准的Android UI组件外观不佳.
任何人都可以提供一些关于如何改善Android应用程序外观和感觉的链接或建议吗?
我试图在我的应用程序中设置按钮的背景颜色,我无法达到我想要的结果...
我试图设置的颜色是holo_green_light(#ff99cc00).为了做到这一点,我正在使用setColorFilter(0xff99cc00, PorterDuff.Mode.MULTIPLY);
我得到的颜色不仅仅是holo_green_lightlightgrey和holo_green_light.
我尝试过使用LightingColorFilter没有太大的成功.
有没有办法以编程方式进行,以便按钮看起来像一个按钮,而不是一个我需要的颜色的扁平矩形.
如何AlertDialog在Android中更改按钮的颜色?
我想使用selector-xml文件更改按钮的背景颜色.我的方法基本上是本页底部示例中的方法:http://developer.android.com/guide/topics/resources/color-list-resource.html
我有一个res/color/button_text.xml,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ffff0000"/> <!-- pressed -->
<item android:state_focused="true"
android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>
Run Code Online (Sandbox Code Playgroud)
我的布局包含以下代码:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_text"
**android:background="@color/button_text"** />
Run Code Online (Sandbox Code Playgroud)
(**只是告诉你我使用android:background而不是android:textcolor)
这段代码崩溃了.它说"二进制XML文件行#4标签需要'drawable'属性或子标签定义drawable.但如果我尝试使用android:textColor,如上面的链接所述,它工作正常.所以它必须是背景问题.我如果没有必要,我不想创建一个9patch-png(基本上我只需要一个"可点击"的矩形,所以我使用带有彩色背景的按钮)
那么,有人会如何实现在android L中展示的循环按钮?还有什么是圆形按钮的技术名称,XML代码将不胜感激.
我有一个ImageButton,背景图像有一些透明度.默认情况下,由于Holo.Light主题,按钮会获得透明像素所在的灰色背景.我尝试通过该setBackgroundColor(Color.TRANSPARENT)方法将按钮的背景颜色设置为透明.这很好,并且做我需要的东西,除了现在我的按钮在聚焦/按下时不再具有浅蓝色并且看起来相当平坦(没有边框,所以它看起来像图像).
我用google搜索,看到你可以像这里解释的那样分配选择器,但这意味着我必须指定每个按钮状态的图像,我不想这样做.我想继承主题中的焦点/按下的颜色,但是将正常的按钮背景(未按下/聚焦时)覆盖为透明而不是灰色.我怎么能实现那个?请提供一个工作示例,因为我尝试了许多不同的组合但没有成功.
编辑 谢谢大家的帮助.我想出了如何使这项工作无需为每个按钮重新创建具有聚焦和按下状态的相同图像!
这是我的解决方案:
我的按钮定义为:
<ImageButton
android:id="@+id/ImageButton05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/button" />
Run Code Online (Sandbox Code Playgroud)
我的后台XML文件(标题为button.xml)定义如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:drawable="@drawable/btn_default_pressed_holo_light"></item>
<item android:drawable="@drawable/network_wifi"></item>
</layer-list>
</item>
<item android:state_focused="true">
<layer-list>
<item android:drawable="@drawable/btn_default_focused_holo_light"></item>
<item android:drawable="@drawable/network_wifi"></item>
</layer-list>
</item>
<item android:state_hovered="true">
<layer-list>
<item android:drawable="@drawable/btn_default_focused_holo_light"></item>
<item android:drawable="@drawable/network_wifi"></item>
</layer-list>
</item>
<item>
<layer-list>
<item android:drawable="@drawable/btn_default_normal_holo_light"></item>
<item android:drawable="@drawable/network_wifi"></item>
</layer-list>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud) 可能重复:
更改交换机的"打开"颜色
ToggleButton当状态从绿色(真)变为红色(假)时,我需要更改颜色.我该如何改变ToggleButton颜色?
android ×10
button ×4
alert ×1
android-xml ×1
background ×1
colors ×1
dialog ×1
imagebutton ×1
xml ×1