回答
9补丁会工作在这里很好,但我会尽量避免他们,因为很难对按键之间没有缝隙(保证金)我做这些:(
你可以尝试有selector
和使用形状每个状态:
形状应该是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#AAFFFFFF"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
你需要创建一个9-patch绘制两个按键之间没有缝隙)。为了让您需要创建XML适当的布局和设置margin为0
+1,thanx的支持,它也帮助我明白了这一点。 – 2011-03-16 12:01:19
您还可以使用的ImageView在XML文件,并给予onClickable和onFocusable真正的N新建的后端代码onClick事件的方法,并给XML的方法的名称,以便不用处理所有形状或按钮的问题,你只是把ImageView的存在,使它像一个button.Here是示例代码为您
<ImageView
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:onClick="testClickEvent"
android:paddingRight="8dip"
android:paddingBottom="8dip"
android:src="@drawable/testImg"/>
正如我在后台方面称,创建方法与这样的迹象,这将做的工作
public void testClickEvent(View v){}
然后实现你想在这个方法中做什么
创建九个补丁绘制其很容易与draw9patch(部分Android设备/工具),然后应用的风格和主题......在this link (Androgames.net)教程应该让你开始。
+1,thanx支持。 – 2011-03-16 12:01:50
链接已经死亡 – Thomas 2013-12-03 08:06:47
寻foursquared源代码和寻找SegmentedButton.java文件,这是实现这些按钮在图像中示出的文件中。
+1 Thiago Thanx为它指出。我已经解决并实施了比这更好的事件:)我仍然会检查它是否好。 :) – 2011-06-23 04:39:50
这里有一些很漂亮的渐变按钮的例子包括预览: http://www.dibbus.com/2011/02/gradient-buttons-for-android/
Thanx分享这个,但我已经遇到了这篇文章4个月前。 – 2011-07-12 04:29:18
别忘了所有其他用户在这里。 – Bachi 2011-08-15 19:39:58
甚至更多:http://www.dibbus.com/2011/08/even-more-gradient-buttons-for-android/ – andresmafra 2014-04-03 23:04:04
我想和大家分享一篇文章是值得落实按钮。 这里是一个文章:http://www.dibbus.com/2011/03/9patch-images-in-android/,它真的不错,真棒文章。
1-创造按下和释放状态
要创建形状,我建议这个伟大的网站会为你做它的形状(与所需的颜色):http://angrytools.com/android/button/
绘制\ botton_shape_pressed.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/pressed_button_background"
android:endColor="@color/pressed_button_background"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
drawable \ botton_shape_released。XML:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/released_button_background"
android:endColor="@color/released_button_background"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
2-创建两个形状
选择抽拉\ botton_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/botton_shape_pressed"
android:state_pressed="true" />
<item android:drawable="@drawable/botton_shape_pressed"
android:state_selected="true" />
<item android:drawable="@drawable/botton_shape_released" />
</selector>
3-使用选择该按钮
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/test"
android:textColor="@color/blue_text"
android:onClick="testOnClickListener"
android:background="@drawable/botton_selector" />
要设置文本的样式,您可以将其添加到strings.xml中
<style name="ButtonText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#ffffff</item>
<item name="android:gravity">center</item>
<item name="android:layout_margin">3dp</item>
<item name="android:textSize">30dp</item>
<item name="android:textStyle">bold</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">2</item>
</style>
,并调用它在main.xml中按钮
style="@style/ButtonText"
,你可以在@绘制创造/ btn_black具有以下玩的另一种方法...
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="#343434" />
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#343434"
android:endColor="#171717"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#171717" />
<corners
android:radius="4dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
button_primary .XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="@color/background"
android:startColor="@color/background" />
<corners android:radius="1dp" />
<stroke
android:width="2px"
android:color="@color/colorPrimary3" />
</shape>
呼叫 风格=“@风格/ button_pr imary“
- 1. 按钮+微调[机器人]
- 2. 按下按钮,机器人状态
- 3. 手机上的联系人按钮和输入样式
- 4. 按钮样式
- 5. 的Windows手机8按钮样式
- 6. 机器人 - 单选按钮和RadioGroup中
- 7. 显示按钮的在机器人
- 8. 机器人:启用/禁用按钮
- 9. 填充图像按钮:机器人
- 10. 机器人如何为按钮
- 11. 延伸按钮机器人,XML布局
- 12. 禁用机器人后退按钮
- 13. 机器人工作室按钮功能()
- 14. 向Azure机器人添加样式
- 15. WPF按钮样式
- 16. 样式和按钮
- 17. jeditable按钮样式
- 18. HTML按钮样式
- 19. Android按钮样式
- 20. AppBar按钮样式
- 21. 按钮样式,css
- 22. CSS按钮样式
- 23. Xamarin按钮样式
- 24. Java按钮样式
- 25. IOS按钮样式
- 26. WPF按钮样式
- 27. Windows Mobile 5.0按钮样式
- 28. IE中的按钮样式
- 29. 模拟按键式的Java机器人
- 30. 让我的按钮样式像AlertDialog按钮样式
+1,thanx为支持,其工作正常 – 2011-03-16 12:00:48
是的最好的你是绝对正确的即将使用9补丁图像,请检查我的答案如下:http://stackoverflow.com/questions/4489069/android-button- style/6659516#6659516 – 2011-07-12 04:30:45
对于半径,如果所有角落都是相同的,可以使用这个小提示:android:radius =“Xdp”。只要添加他的代码是好的。 – Nemka 2014-07-29 15:57:15