自定义按钮
来源:互联网 发布:西门子plc编程电缆 编辑:程序博客网 时间:2024/06/06 03:43
<com.awtrip.view.CustomRadioButton
android:id="@+id/sousuo_CustomRadioButton"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:background="@drawable/lanseanniu_selector"
custom:LeftTextDrawable="@drawable/jiudianyuding_sousuo"
custom:Text="搜索"
custom:TextSize="8sp"
custom:TextColor="@color/baise" />
lanseanniu_selector
<?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="#8858B1E5"/>
<corners android:radius="5dp" />
</shape>
</item>
<item android:state_pressed="false">
<shape >
<solid android:color="#FF58B1E5"/>
<corners android:radius="5dp" />
</shape>
</item>
</selector>
public class CustomRadioButton extends RelativeLayout {attrs
private String text;
private Drawable drawable, leftDrawable;
private int textColor;
private float textSize;
private TextView textView;
private ImageView imageView, leftImageView;
/**
* @param context
* @param attrs
*/
public CustomRadioButton(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.view_custom_radiobutton, this);
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CustomRadioButton);
text = ta.getString(R.styleable.CustomRadioButton_Text);
textColor = ta.getColor(R.styleable.CustomRadioButton_TextColor, 0);
drawable = ta.getDrawable(R.styleable.CustomRadioButton_TextDrawable);
leftDrawable = ta.getDrawable(R.styleable.CustomRadioButton_LeftTextDrawable);
textSize = ta.getDimension(R.styleable.CustomRadioButton_TextSize, 14);
ta.recycle();
setGravity(Gravity.CENTER);
textView = (TextView) findViewById(R.id.textView);
imageView = (ImageView) findViewById(R.id.rightImage);
leftImageView = (ImageView) findViewById(R.id.leftImage);
textView.setText(text);
textView.setTextSize(textSize);
textView.setTextColor(textColor);
imageView.setImageDrawable(drawable);
leftImageView.setImageDrawable(leftDrawable);
}
public void setTextColor(int colorId) {
textView.setTextColor(colorId);
}
public void setImageDrawable(Drawable drawable) {
imageView.setImageDrawable(drawable);
}
}
<declare-styleable name="CustomRadioButton">
<attr name="TextDrawable" format="reference"></attr>
<attr name="LeftTextDrawable" format="reference"></attr>
<attr name="TextColor" format="color"></attr>
<attr name="TextSize" format="dimension"></attr>
<attr name="Text" format="string"></attr>
</declare-styleable>
- <?xml version="1.0" encoding="utf-8"?>
- <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
- <item>
- <shape
- android:shape="rectangle">
- <solid android:color="#FF0000" />
- <corners android:radius="30dp"/>
- </shape>
- </item>
- <item android:left="30dp"
- >
- <shape
- android:shape="rectangle">
- <solid android:color="#FF0000" />
- </shape>
- </item>
- </layer-list>
第一种:
现在drawable/下创建semi_round_backgroud.xml:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:color="@color/colorAccent">
<corners
android:radius="60dip"
/>
<stroke
android:width="0dp"
android:color="@color/colorAccent" />
<solid
android:color="@color/colorAccent" />
</shape>
第二种:
semi2.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorAccent" />
<size android:height="30dp" />
<corners
android:bottomRightRadius="30dp"
android:bottomLeftRadius="30dp"
android:topRightRadius="30dp"
android:topLeftRadius="30dp"
/>
</shape>
0 0
- 自定义按钮
- 自定义按钮
- 自定义按钮
- 自定义按钮
- 自定义按钮
- 自定义按钮
- 自定义按钮
- 自定义按钮
- 自定义按钮
- 自定义按钮
- 自定义按钮控件-图标按钮
- 自定义按钮控件-热点按钮
- 自定义按钮控件-圆形按钮
- 自定义按钮组,需自定义按钮配合
- 自定义控件--图片按钮
- FCKeditor添加自定义按钮
- DataGrid自定义导航按钮
- 自定义datagrid分页按钮
- MySQL快速入门04----数据类型
- 第6课:Scala常用数据结构实战
- 图片预览可以点击查看大图
- opengl函数(0)
- 欢迎使用CSDN-markdown编辑器
- 自定义按钮
- stl string 简单应用
- 异常处理
- 第七课:scala继承实战
- Spring加载classpath与classpath*的过程剖析
- Android View事件分发
- 最短路(Dijkstra算法)
- 方便记录
- 快速入门Openstack,无脑多节点部署Mitaka(4)--Glance部署