Skip to content

Repository files navigation

PerfectTextView

完善了TextView 四个方向的Drawable设置,可在布局中设置大小和间距,并且可以设置点击,双击,长按监听

GitHub starsGitHub forksGitHub issuesGitHub license

show

支持的功能

1、四个位置的图片在布局中也可单独设置大小

2、四个位置的图片可以单独设置距离文字的距离

3、四个位置的图片可以设置点击、双击、长按事件监听

4、支持设置选中(setSelected)时的文本

5、支持单独为四个位置中的一个设置大小、图片、距离文本距离

6、支持为文本区域设置背景

第一步,根目录build.gradle

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

第二步,需要引用的build.gradle (最新版本

dependencies {
implementation 'com.github.FlyJingFish:PerfectTextView:1.2.0'
}

第三步,使用说明

 <com.flyjingfish.perfecttextviewlib.PerfectTextView
android:id="@+id/hollowTextView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"android:background="@drawable/bg_select"android:gravity="center"android:textStyle="bold"android:padding="10dp"android:textColor="@color/press_color"android:layout_marginTop="10dp"app:perfect_drawableStart_width="40dp"app:perfect_drawableStart_height="40dp"app:perfect_drawableEnd_width="100dp"app:perfect_drawableEnd_height="100dp"app:perfect_drawableTop_width="20dp"app:perfect_drawableTop_height="20dp"app:perfect_drawableBottom_width="50dp"app:perfect_drawableBottom_height="50dp"android:drawablePadding="40dp"app:perfect_drawableStart_padding="20dp"app:perfect_drawableEnd_padding="10dp"app:perfect_drawableTop_padding="30dp"app:perfect_drawableBottom_padding="30dp"app:perfect_selected_text="@string/app_name"app:perfect_text_background="@drawable/bg_text_press"app:perfect_text_background_scope="wrappedText"android:drawableTop="@drawable/press_icon"android:drawableStart="@drawable/select_icon"android:drawableEnd="@drawable/select_icon"android:drawableBottom="@drawable/press_icon"android:textSize="30sp"/>

属性一览

attrformatdescription
perfect_drawableStart_widthdimension左侧(Rtl:右侧)图片宽度
perfect_drawableStart_heightdimension左侧(Rtl:右侧)图片高度
perfect_drawableStart_paddingdimension左侧(Rtl:右侧)图片距离文本距离
perfect_drawableEnd_widthdimension右侧(Rtl:左侧)图片宽度
perfect_drawableEnd_heightdimension右侧(Rtl:左侧)图片高度
perfect_drawableEnd_paddingdimension右侧(Rtl:左侧)图片距离文本距离
perfect_drawableLeft_widthdimension左侧图片宽度
perfect_drawableLeft_heightdimension左侧图片高度
perfect_drawableLeft_paddingdimension左侧图片距离文本距离
perfect_drawableRight_widthdimension右侧图片宽度
perfect_drawableRight_heightdimension右侧图片高度
perfect_drawableRight_paddingdimension右侧图片距离文本距离
perfect_drawableTop_widthdimension上侧图片宽度
perfect_drawableTop_heightdimension上侧图片高度
perfect_drawableTop_paddingdimension上侧图片距离文本距离
perfect_drawableBottom_widthdimension下侧图片宽度
perfect_drawableBottom_heightdimension下侧图片高度
perfect_drawableBottom_paddingdimension下侧图片距离文本距离
perfect_selected_textstring选中时文本(原来的 text 是默认文本)
perfect_selected_hintstring选中时提示文本(原来的 hint 是默认文本)
perfect_text_backgroundreference/color文本区域背景
perfect_text_background_scopeenumwrappedText(紧紧包裹文本)/fitDrawablePadding(适应到四个方向的Drawable并与drawable距离为drawablePadding)

设置监听(部分示例)

//点击左侧图标监听binding.hollowTextView.setOnDrawableStartClickListener(v -> {
Toast.makeText(this,"setOnDrawableStartClickListener",Toast.LENGTH_SHORT).show();
});
//长按左侧图标监听binding.hollowTextView.setOnDrawableStartLongClickListener(v -> {
Toast.makeText(this,"setOnDrawableStartLongClickListener",Toast.LENGTH_SHORT).show();
returntrue;//false则会继续回调点击事件
});
//双击左侧图标监听binding.hollowTextView.setOnDrawableStartDoubleClickListener(v -> {
Toast.makeText(this,"setOnDrawableStartDoubleClickListener",Toast.LENGTH_SHORT).show();
});

更多功能

attrdescription
setTextBackground文本区域背景
setTextBackgroundResource文本区域背景
setTextBackgroundColor文本区域背景
setTextBackgroundScope文本区域背景显示区域
setDrawableStartWidthHeight/setDrawableEndWidthHeight等等单独为四个位置之一设置图片宽高
setDrawableStartPadding/setDrawableEndPadding等等单独为四个位置之一设置图片距离文本的距离
setDrawableStartSelected/setDrawableEndSelected等等图片选中
setDrawableStart/setDrawableEnd等等单独为四个位置之一设置图片
setOnDrawableStartClickListener/setOnDrawableEndClickListener等等单独为四个位置之一设置点击监听
setOnDrawableStartLongClickListener/setOnDrawableEndLongClickListener等等单独为四个位置之一设置长按监听
setOnDrawableStartDoubleClickListener/setOnDrawableEndDoubleClickListener等等单独为四个位置之一设置双击监听
setOnClickListener(OnClickListener l, ClickScope clickScope)点击监听,clickScoped点击的区域范围
setOnLongClickListener(OnLongClickListener l, ClickScope clickScope)长按监听,clickScoped点击的区域范围
setOnDoubleClickListener(OnClickListener l, ClickScope clickScope)双击监听,clickScoped点击的区域范围
setSelectedText设置选中文本
setText默认文本
setSelectedHint设置选中时提示文本(不建议再使用setHint方法了)
setDefaultHint选中未选中时提示文本(不建议再使用setHint方法了)
setSelectedIgnoreDrawable设置选中状态不会改变四个位置的状态(原来的 setSelected 方法会改变)

最后推荐我写的另外一些库

About

🔥🔥🔥完善了TextView 四个方向的Drawable设置,可在布局中设置大小和间距,并且可以设置点击,双击,长按监听

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages