Button 按钮的颜色设置问题? 为什么 Button 在设置默认状态下,和设置背景颜色以后,形状都改变了? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的意思是设置背景颜色后button的形状就变了?不应该吧,我给button加图片和设置文字都不会变形的 你的意思是设置背景颜色后button的形状就变了?不应该吧,我给button加图片和设置文字都不会变形的 加图片和文字 是不变 ,可是 <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算" /> 和 <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计算" android:background="#ffffff" />形状不一样了,变的很难看... 哦...android:background一般都是设置图片的,但是你设置为颜色后,实际上是将button按照矩形区域做填充而已,肯定没有圆角边儿了..... 不用呢,你直接指定android:layout_width="50px" android:layout_height="50px"就Ok啦 你要圆角的效果那就需要用图片合成了。我一般用三张,及三个控制来模拟有圆角的Button LS能说明白点怎么设置么?thx 形状变是因为你高和宽都使用了wrap_content。这样当背景变化后,会重新计算图形大小的。默认的button使用的是一个点九的图,而你改成color肯定会导致形状不一样的。如果需要固定背景,你可以使用一个图片作为背景。如果还是要用color那么,就要限制高宽,但是这样当文字改变时,可能就会显示不全了。 一般是一个xml文件,里面用selector来根据状态选择不同的图片。然后把这个selector作为资源付给控件作为背景即可。你可以看看文档,关于resource的介绍,或者找源码在有些应用的drawable目录下就有使用的例子。 就是在android 中设置一个drawable xml 在你的main.xml 中调用(就是直接drawable得到)设置的时候有个 选择器 selector 然后进去设置你的button参数,可以自己调试各种圆角! 在drawable下新建一个custom_button.xml, 按钮的android:background="drawable/custom_button" 代码如下:<?xml version="1.0" encoding="UTF-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape> <gradient android:startColor="#116eb0" android:endColor="#116eb0" android:angle="270" /> <stroke android:width="1dp" android:color="#dcdcdc" /> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> <item android:state_focused="true"> <shape> <gradient android:startColor="#116eb0" android:endColor="#116eb0" android:angle="270" /> <stroke android:width="1dp" android:color="#dcdcdc" /> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> <item> <shape> <gradient android:startColor="#1e87fb" android:endColor="#179bff" android:angle="270" /> <stroke android:width="1dp" android:color="#fad3cf" /> <corners android:radius="5dp" /> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item></selector> 给button设置背景图就变成图片那样的button了 jni怎么样传递一个字符串数组? 菜鸟求助:安卓模拟器如何设置分辨率为1920*1080 关于XML解析天气预报 android widget如何跳转到系统的时间日期设置界面 如何发布一条新微博?? attach of thread 'binder thread #3'failed pull解析xml [Android]如何将多个APK或者其他文件打包成一个安装文件? 介绍几款好点的反编译软件 androidstudio+NDK 的曙光何时到来 apk重新打包,相信大家都想解决这个问题 初来咋到,新手求关照
不应该吧,我给button加图片和设置文字都不会变形的
不应该吧,我给button加图片和设置文字都不会变形的
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="计算"
/> 和 <Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="计算"
android:background="#ffffff"
/>
形状不一样了,变的很难看...
android:layout_width="50px"
android:layout_height="50px"就Ok啦
LS能说明白点怎么设置么?
thx
默认的button使用的是一个点九的图,而你改成color肯定会导致形状不一样的。如果需要固定背景,你可以使用一个图片作为背景。如果还是要用color那么,就要限制高宽,但是这样当文字改变时,可能就会显示不全了。
一般是一个xml文件,里面用selector来根据状态选择不同的图片。然后把这个selector作为资源付给控件作为背景即可。
你可以看看文档,关于resource的介绍,或者找源码在有些应用的drawable目录下就有使用的例子。
设置的时候有个 选择器 selector 然后进去设置你的button参数,可以自己调试各种圆角!
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient android:startColor="#116eb0" android:endColor="#116eb0" android:angle="270" />
<stroke android:width="1dp" android:color="#dcdcdc" />
<corners android:radius="5dp" />
<padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient android:startColor="#116eb0" android:endColor="#116eb0" android:angle="270" />
<stroke android:width="1dp" android:color="#dcdcdc" />
<corners android:radius="5dp" />
<padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient android:startColor="#1e87fb" android:endColor="#179bff" android:angle="270" />
<stroke android:width="1dp" android:color="#fad3cf" />
<corners android:radius="5dp" />
<padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />
</shape>
</item>
</selector>