LZ-Say:有時(shí)候覺得,開發(fā)真心不容易。想做一個(gè)好的開發(fā),不僅僅會(huì)敲代碼,造輪子,更多個(gè)人覺得調(diào)整心態(tài),畢竟人和人是不一樣的。。。心塞
前言
今天為大家?guī)硪粋€(gè)簡(jiǎn)單的小玩意,沒什么技術(shù)含量,做這個(gè)的初衷是個(gè)人嫌棄UI給的設(shè)計(jì)圖,另一方便是希望app能更人性化,大家可以一起來看下UI給的圖。
大體一看,大家可能會(huì)說,沒啥毛病啊,不就是一個(gè)輸入框么?
是的,如果按照我之前的想法,我個(gè)人是絕對(duì)會(huì)老老實(shí)實(shí)按照UI給定的圖來,但是經(jīng)過一些事之后,我卻不這么想了。
那么,我們看看,這個(gè)東西是不是缺點(diǎn)啥呢?
有的兄弟們就說了,在右下角加一個(gè)<font color=#FF0000>顯示字?jǐn)?shù)</font>的唄。
嘿嘿,,,說干就干~
簡(jiǎn)單分析及Coding
干之前,我們先來簡(jiǎn)單分析下我們要做的東西,先給大家簡(jiǎn)單畫個(gè)效果---江湖人稱UI設(shè)計(jì)圖~
如果最多用戶只能輸入140個(gè)字符,并且當(dāng)輸入字符個(gè)數(shù)等于140個(gè)時(shí),提示一下。
實(shí)現(xiàn)這個(gè),主要分以下幾步:
1. 首先編寫一個(gè)shape文件,這里面當(dāng)然要指定圓角弧度以及邊框顏色寬度;
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="@dimen/dp_1"
android:color="@color/color_c9"/>
<corners android:radius="@dimen/dp_3"/>
</shape>
2. 編寫我們布局文件。內(nèi)容為:相對(duì)布局中包含EditText以及TextView,具體如下:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_circle_while_bg">
<EditText
android:id="@+id/id_editor_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@null"
android:gravity="top"
android:hint="@string/string_editor_detail_hint"
android:maxLength="140"
android:minLines="6"
android:padding="@dimen/dp_10"
android:textColor="@color/color_c6"
android:textColorHint="@color/color_c9"
android:textSize="@dimen/sp_14"/>
<TextView
android:id="@+id/id_editor_detail_font_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/id_editor_detail"
android:paddingBottom="@dimen/dp_5"
android:paddingRight="@dimen/dp_15"
android:text="@string/string_editor_detail_default_font"
android:textColor="@color/color_c9"
android:textSize="@dimen/sp_14"/>
</RelativeLayout>
3.activity邏輯校驗(yàn)
由于LZ項(xiàng)目中使用的是黃油刀,下面就直接從項(xiàng)目拷貝了~
有興趣的同志可以看看之前寫的有關(guān)黃油刀基本使用,地址如下:
@OnTextChanged(value = R.id.id_editor_detail, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
public void editTextDetailChange(Editable editable) {
int detailLength = editable.length();
idEditorDetailFontCount.setText(detailLength + "/140");
if (detailLength == 139) {
islMaxCount = true;
}
// 不知道為什么執(zhí)行倆次,所以增加一個(gè)標(biāo)識(shí)符去標(biāo)識(shí)
if (detailLength == 140 && islMaxCount) {
UIHelper.getShortToast(self, (String) StringUtils.getResourceContent(self, Convention.RESOURCE_TYPE_STRING, R.string.string_editor_detail_input_limit));
islMaxCount = false;
}
}
4.來來來,一起看效果~
4.1 當(dāng)用戶輸入時(shí):
4.2 當(dāng)用戶刪除時(shí):
4.3 當(dāng)輸入達(dá)到上限時(shí):
結(jié)束
基本介紹到此結(jié)束~