我的新书《Android App开发入门与实战》已于2020年8月由人民邮电出版社出版,欢迎购买。点击进入详情
项目地址
https://github.com/ddnosh/android-tiny-ui
解决方案
- 使用view handler去处理每个view的AttributeSet
功能介绍
- 可以在xml里面设置view的属性;
- 可以在Java代码里设置view的属性;
用法
<com.androidwind.ui.view.TinyTextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TinyTextView"
app:background_normal="@color/colorPrimary"
app:background_pressed="@color/colorPrimaryDark"
app:corner_radius="6dp" />
public void BtnClick(View view) {
TinyTextView ttv = findViewById(R.id.ttv);
//获取handler
TinyTextViewHandler handler = ttv.getViewHandler();
handler.setBackgroundColorNormal(getResources().getColor(android.R.color.holo_red_dark))
.setBorderColorNormal(getResources().getColor(android.R.color.holo_orange_light))
.setBorderWidthNormal(12)
.setCornerRadius(25);
}