第三方开源库-->SuperTextView
Posted Kevin_小飞象
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第三方开源库-->SuperTextView相关的知识,希望对你有一定的参考价值。
SuperTextView 是一个功能强大的 View,可以满足日常大部分布局样式,开发者可已自行组合属性配置出属于自己风格的样式!可能描述起来没有概念,还是直接看效果图吧!
效果图
如何使用
android Studio 导入方法,添加 Gradle 依赖
先在项目根目录的 build.gradle 的 repositories 添加:
allprojects
repositories
...
maven url "https://jitpack.io"
然后在 dependencies 添加:
dependencies
...
compile 'com.github.lygttpod:SuperTextView:2.4.6'
1 布局中如何使用
<com.allen.supertextviewlibrary.SuperTextView
android:id="@+id/super_tv"
android:layout_width="match_parent"
android:layout_height="80dp"
stv:sLeftBottomTextColor2="@color/colorAccent"
stv:sLeftBottomTextString="招商银行(8888)"
stv:sLeftBottomTextString2="限额说明>>"
stv:sLeftIconRes="@drawable/bank_zhao_shang"
stv:sLeftTopTextString="银行卡支付"
stv:sRightCheckBoxRes="@drawable/circular_check_bg"
stv:sRightCheckBoxShow="true"
stv:sLineShow="bottom"
/>
注意:
1、上下的线可以通过 sLineShow 设置 有四种显示方式 none,top,bottom,both
2、通过设置 sUseRipple=true 开启水波效果
示列:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:stv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
stv:sLeftTextString="帐号管理"
stv:sRightIconRes="@drawable/arrow_right_red" />
<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
stv:sLeftTextString="通知设置"
stv:sRightIconRes="@drawable/arrow_right_red" />
<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
stv:sLeftTextString="通用设置"
stv:sRightIconRes="@drawable/arrow_right_red" />
<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
stv:sLeftTextString="隐私与安全"
stv:sRightIconRes="@drawable/arrow_right_red" />
<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
stv:sLeftTextString="设置中心"
stv:sRightIconRes="@drawable/arrow_right_red" />
<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="20dp"
stv:sLeftTextString="意见反馈"
stv:sRightIconRes="@drawable/arrow_right_red" />
<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
stv:sLeftTextString="关于微博"
stv:sRightIconRes="@drawable/arrow_right_red" />
</LinearLayout>
</ScrollView>
</LinearLayout>
2 代码中如何使用
/**
* 可以通过链式设置大部分常用的属性值
*/
superTextView.setLeftTopString("")
.setLeftString("")
.setLeftBottomString("")
.setCenterTopString("")
.setCenterString("")
.setCenterBottomString("")
.setRightTopString("")
.setRightString("")
.setRightBottomString("")
.setLeftIcon(0)
.setRightIcon(0)
.setCbChecked(true)
.setCbBackground(null)
.setLeftTvDrawableLeft(null)
.setLeftTvDrawableRight(null)
.setCenterTvDrawableLeft(null)
.setCenterTvDrawableRight(null)
.setRightTvDrawableLeft(null)
.setRightTvDrawableRight(null);
superTextView.setShapeCornersRadius(20)
.setShapeCornersTopLeftRadius(20)
.setShapeCornersBottomLeftRadius(20)
.setShapeCornersTopRightRadius(20)
.setShapeCornersBottomRightRadius(20)
.setShapeStrokeColor(getResources().getColor(R.color.colorPrimary))
.setShapeStrokeWidth(1)
.setShapeSrokeDashWidth(1)
.setShapeStrokeDashGap(5)
.setShapeSolidColor(getResources().getColor(R.color.white))
.setShapeSelectorNormalColor(getResources().getColor(R.color.red_btn))
.setShapeSelectorPressedColor(getResources().getColor(R.color.gray))
.useShape();//设置完各个参数之后这句调用才生效
//点击事件:
/**
* 根据实际需求对需要的View设置点击事件
*/
/**
* 根据实际需求对需要的View设置点击事件
*/
superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener()
@Override
public void onClickListener(SuperTextView superTextView)
string = "整个item的点击事件";
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setLeftTopTvClickListener(new SuperTextView.OnLeftTopTvClickListener()
@Override
public void onClickListener()
string = superTextView.getLeftTopString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setLeftTvClickListener(new SuperTextView.OnLeftTvClickListener()
@Override
public void onClickListener()
string = superTextView.getLeftString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setLeftBottomTvClickListener(new SuperTextView.OnLeftBottomTvClickListener()
@Override
public void onClickListener()
string = superTextView.getLeftBottomString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setCenterTopTvClickListener(new SuperTextView.OnCenterTopTvClickListener()
@Override
public void onClickListener()
string = superTextView.getCenterTopString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setCenterTvClickListener(new SuperTextView.OnCenterTvClickListener()
@Override
public void onClickListener()
string = superTextView.getCenterString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setCenterBottomTvClickListener(new SuperTextView.OnCenterBottomTvClickListener()
@Override
public void onClickListener()
string = superTextView.getCenterBottomString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setRightTopTvClickListener(new SuperTextView.OnRightTopTvClickListener()
@Override
public void onClickListener()
string = superTextView.getRightTopString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setRightTvClickListener(new SuperTextView.OnRightTvClickListener()
@Override
public void onClickListener()
string = superTextView.getRightString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setRightBottomTvClickListener(new SuperTextView.OnRightBottomTvClickListener()
@Override
public void onClickListener()
string = superTextView.getRightBottomString();
Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show();
).setLeftImageViewClickListener(new SuperTextView.OnLeftImageViewClickListener()
@Override
public void onClickListener(ImageView imageView)
Toast.makeText(ClickActivity.this, "左边图片", Toast.LENGTH_SHORT).show();
).setRightImageViewClickListener(new SuperTextView.OnRightImageViewClickListener()
@Override
public void onClickListener(ImageView imageView)
Toast.makeText(ClickActivity.this, "右边图片", Toast.LENGTH_SHORT).show();
);
superTextView_cb.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener()
@Override
public void onClickListener(SuperTextView superTextView)
superTextView.setCbChecked(!superTextView.getCbisChecked());
).setCheckBoxCheckedChangeListener(new SuperTextView.OnCheckBoxCheckedChangeListener()
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
Toast.makeText(ClickActivity.this, "" + isChecked, Toast.LENGTH_SHORT).show();
);
superTextView_switch.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener()
@Override
public void onClickListener(SuperTextView superTextView)
superTextView.setSwitchIsChecked(!superTextView.getSwitchIsChecked());
).setSwitchCheckedChangeListener(new SuperTextView.OnSwitchCheckedChangeListener()
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
Toast.makeText(ClickActivity.this, "" + isChecked, Toast.LENGTH_SHORT).show();
);
3 属性
4. 效果图的布局:
activity_demo_one.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:stv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"以上是关于第三方开源库-->SuperTextView的主要内容,如果未能解决你的问题,请参考以下文章
Android 让SuperTextView支持边框线颜色渐变