自定义textview背景图
来源:互联网 发布:sqlserver安装错误 编辑:程序博客网 时间:2024/05/16 09:35
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:IWindTopBgView="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginBottom="2dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:orientation="horizontal">
<wind.ui.IWindTopBgView
android:id="@+id/btn_chat"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_marginRight="1dip"
android:layout_weight="1"
android:gravity="center"
android:padding="4dip"
android:text="聊天"
android:textColor="@color/color_white"
android:textSize="13dip"
IWindTopBgView:borderRectColor="@color/iwindtab_red" />
<wind.ui.IWindTopBgView
android:id="@+id/btn_contact"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_marginLeft="1dip"
android:layout_weight="1"
android:gravity="center"
android:padding="4dip"
android:text="通讯录"
android:textColor="@color/color_white"
android:textSize="13dip"
IWindTopBgView:borderRectColor="@color/iwindtab_orange" />
</LinearLayout>
<ImageView
android:id="@+id/iv_unread"
android:layout_width="10dip"
android:layout_height="10dip"
android:layout_gravity="center_horizontal"
android:layout_marginRight="20dip"
android:layout_marginTop="3dip"
android:src="@drawable/iwind_update_notice"
android:visibility="invisible" />
</FrameLayout>
</LinearLayout>
values文件夹下新建attr文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="searchEditTextStyleable">
<attr name="btnBackground" format="reference" />
<attr name="btnText" format="reference|string" />
<attr name="btnTextcolor" format="reference|color" />
<attr name="btnTextsize" format="dimension"/>
<attr name="btnVisibility" format="string"/>
</declare-styleable>
<declare-styleable name="IWindTopBgView" >
<attr name="borderRectColor" format="reference|color"/>
</declare-styleable>
</resources>
自定义控件
public class IWindTopBgView extends TextView {
private int mBorderColor = Color.TRANSPARENT;
private Paint mPaint;
public IWindTopBgView(Context context) {
this(context,Color.TRANSPARENT);
}
public IWindTopBgView(Context context, int color) {
super(context);
mBorderColor = color;
init(context);
}
public IWindTopBgView(Context context, AttributeSet attrs) {
super(context, attrs);
final TypedArray attributes = context.getTheme().obtainStyledAttributes(attrs, R.styleable.IWindTopBgView, 0, 0);
mBorderColor = attributes.getColor(R.styleable.IWindTopBgView_borderRectColor, Color.TRANSPARENT);
init(context);
}
public void setBorderColor(int color){
mPaint.setColor(mBorderColor);
}
private void init(Context context) {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setColor(mBorderColor);
mPaint.setStyle(Paint.Style.STROKE);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
//绘制矩形框
canvas.drawRect(0,0,getWidth(),getHeight(),mPaint);
}
}
- 自定义textview背景图
- 高德地图自定义infowindow样式,textview设置文字在背景图中的位置
- 制作光盘自定义背景图
- 自定义UISearchBar的背景图
- IOS 自定义UISearchBar的背景图
- 如何自定义简单的背景图
- 自定义textview
- 自定义textview
- 自定义TextView
- 自定义TextView
- TextView自定义
- 自定义TextView
- 自定义textView
- 自定义TextView
- 自定义TextView
- 自定义TextView
- android 自定义Dialog(背景图等)
- android 自定义Dialog(背景图等)
- GCC主要数据结构之struct gcov_info
- Spring声明式事务配置管理方法
- 例题:C++中删除链表中的奇数元素
- tensorflow学习笔记十五:tensorflow官方文档学习 TensorBoard: Embedding Visualization
- V4L2应用程序框架学习笔记
- 自定义textview背景图
- calendar中的时间格式
- 动态申请二维数组
- C++中的static关键字的总结(转)
- iOS随笔之获取可用空间及某个文件或文件夹的大小及判断文件是否存在
- soa-面向服务项目搭建
- php自定义错误处理器
- sql
- JavaScript常用API总结