我需要设计Android应用程序的按钮为矩形,并且是半个颜色,另一半。当然是在XML中。
我试过这个:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding
android:left="7dp"
android:top="15dp"
android:right="7dp"
android:bottom="15dp" />
<gradient
android:startColor="#a241cb"
android:endColor="#a241cb"
android:type="linear"
android:angle="90"/>
<stroke>
android:width="1dip"
android:color="#a241cb" />
<corners android:radius="0dp" />
</shape>
感谢任何帮助
答案 0 :(得分:0)
Try this:
frist在drawable文件夹中创建background.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#4A225E"
android:endColor="#4C4064"
android:centerColor="#B4AFC5"/>
</shape>
然后设置按钮背景为我工作
答案 1 :(得分:0)
你可以通过使用渐变作为背景来实现这一点。
使用它
在res/drawable
文件夹下创建一个新的XML文件,并将其命名为button_bg.xml
。
的 button_bg.xml 强>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#D5DDE0"
android:centerColor="#e7e7e8"
android:endColor="#CFCFCF"
android:angle="270" />
</shape>
现在将它用于Button
,如下所示:
android:background="@drawable/button_bg"
希望它有所帮助。 :)
答案 2 :(得分:0)
使用这样的9补丁(将其保存在您的drawable文件夹中 bw_bg.9.png ):
你可以得到这样的结果:
示例布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00f"
>
<Button
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:background="@drawable/bw_bg"
/>
</RelativeLayout>
不要介意尺寸(它在Froyo 2.8英寸屏幕上运行) 也不要介意通知(它来自另一个正在运行的应用程序)。