android 设置shape不起作用
来源:互联网 发布:java编程思想 猎豹 编辑:程序博客网 时间:2024/05/16 14:10
andorid布局中通过xml文件通过shape设置textview圆角边框。但是不起作用。弄了好久才发现问题。
希望遇到这个问题的朋友少走弯路。
android 在布局文件中设置了textview的背景属性。
<TextView android:id="@+id/login" android:layout_width="match_parent" android:layout_height="50dp" android:layout_margin="15dp" android:background="@drawable/liveshape" android:gravity="center" android:text="@string/remote_live_login" android:textSize="@dimen/live_text_size" android:textColor="@color/white" />
liveshape.xml文件如下
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="false" android:state_enabled="true"> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/loginColor" /> <stroke android:width="1dp" android:color="#60000000" /> <corners android:radius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp"/> </shape> </item> <item > <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/gray" /> <stroke android:width="1dp" android:color="#e0000000" /> <corners android:radius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp"/> </shape> </item></selector>刚开始以为需要设置topLeftRadius、topRightRadius、、、但是加上依然不正常显示。
最后发现原来是代码的问题。在activity加载后又重新设置了它的bacgroungResources,所以没有起作用。
mLoginView.setBackground(getResources().getDrawable(R.drawable.remotelive));
mLoginView.setBackgroundColor(getResources().getColor(R.color.white));
mLoginView.setBackgroundResource(R.drawable.bordershape);
上面的这三个方法任何一个都会到重新设置控件背景,导致xml设置的shape不起作用。
把这些代码注释掉就ok了。
2 1
- android 设置shape不起作用
- Android 爬坑-shape不起作用
- Android动态设置Shape
- Android 动态设置Shape
- android actionBar logo设置不起作用
- Android GridView 设置间距不起作用
- Android 设置bitmap、selector、shape
- android LinearLayout设置selector不起作用解决
- Android 给Animation设置setRepeatMode不起作用
- android中ToolBar设置setNavigationOnClickListener()方法不起作用
- android LinearLayout设置selector不起作用解决
- android中ToolBar设置setNavigationOnClickListener()方法不起作用
- android LinearLayout设置selector不起作用问题解决方案
- Android使用Shape进行渐变设置
- android shape 常用到属性的设置
- Android代码设置Shape,corners,Gradient
- Android代码设置Shape,corners,Gradient
- android shape corners 设置无效的解决
- Java设计模式值简单工厂设计模式
- linux进程间通讯的几种方式的特点和优缺点,和适用场合。
- Angular2 and Electron - The definitive guide
- android webview H5开发若干问题之问题二:cookie问题
- 杭电1222
- android 设置shape不起作用
- 阿里云缓存服务器里面的一个坑
- python实践系列之(一)安装 python/pip/numpy/matplotlib
- jQuery自动补全小数
- 远程调试Android/IOS设备/微信网页方法汇总
- Activity如何传递数据
- 离散FFT和图像二维FFT变换的java实现
- Swift简介和添加Mark的方法
- 常用的adb指令(慢慢更新)