MaterialEditText 控件学习
這個視圖原始框架地址:https://github.com/rengwuxian/MaterialEditText
指導(dǎo)手冊:http://www.rengwuxian.com/post/materialedittext#content
接下來是我學(xué)習(xí)和總結(jié)的時候了:
1,沒配置相關(guān)屬性參數(shù):
<com.yh.materialeditlibrary.MaterialEditTextandroid:id="@+id/basicEt"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:hint="Basic" />效果:
設(shè)置為不可用狀態(tài):
?
enableBt.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) { basicEt.setEnabled(!basicEt.isEnabled());enableBt.setText(basicEt.isEnabled() ? "DISABLE" : "ENABLE");}});效果:
?
1 BaseColor
文檔里面是這么說的:
Base Color 被用作背景線的顏色、主字體的顏色(透明度被重置為87%)和提示字體的顏色(透明度被重置為26%)。你可以使用app:baseColor(xml) 或者?setBaseColor()(java) 來指定 Base Color 。Base Color 的默認(rèn)值為純黑
?
修改為紅色:
<com.yh.materialeditlibrary.MaterialEditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Custom Base Color"app:baseColor="@color/red" />效果:
?
2 Primary Color
自定義Primary Color
Primary Color 被用作激活狀態(tài)的輸入框背景色、高亮的Floating Label色和底部省略號的顏色。你可以使用?app:primaryColor?(xml) 或者?setPrimaryColor()(java) 來指定 Primary Color。如果沒有設(shè)置Primary Color,默認(rèn)將使用 Base Color 來替代
也就是獲取焦點狀態(tài)時的底部顏色
默認(rèn)顏色為紅色,點擊后顯示為綠色的底.
<com.yh.materialeditlibrary.MaterialEditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Custom Primary Color"app:baseColor="@color/red"app:primaryColor="@color/green" />沒點擊狀態(tài):
點擊后:
?
3 Floating Label
Floating Label 有三種模式:?none?,?normal?,?highlight?。 你可以使用?app:floatingLabel?(xml) 或者setFloatingLabel()?(java) 來設(shè)置 Floating Label 的模式
從效果中明顯看出是在EditText上面顯示的問題的高亮程度,none,壓根不顯示,normal 默認(rèn)的亮度,hightlight 高亮顯示
none:
xml:
<com.yh.materialeditlibrary.MaterialEditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Floating Label"app:floatingLabel="none" /> <com.yh.materialeditlibrary.MaterialEditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Highlight Floating Label"app:floatingLabel="normal" /> <com.yh.materialeditlibrary.MaterialEditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Highlight Floating Label"app:floatingLabel="highlight" />?
4 singleLineEllipsis
當(dāng)設(shè)置顯示底部省略號后,控件會在文字向左滾動時在底部左側(cè)顯示一個三個點的省略號,點擊省略號將自動把光標(biāo)置于字符串的開始處。你可以通過?app:singleLineEllipsis=true?(xml) 或者?setSingleLineEllipsis()?(java) 來設(shè)置它。這個屬性將自動設(shè)置android:singleLine?為 true
?
首先這個控件在不選中是不顯示...的,而且滑動到最左側(cè),...小時,滑向右側(cè),...出現(xiàn)
<com.yh.materialeditlibrary.MaterialEditTextandroid:id="@+id/singleLineEllipsisEt"android:layout_width="match_parent"android:layout_height="wrap_content"android:hint="Single Line Ellipsis"android:text="soyoungboy is beautiful ,so cool ,so nice ,so smart"app:singleLineEllipsis="true" />效果:
5 ?maxCharacters
設(shè)置字符數(shù)限制后,控件右下角會顯示已輸入字符數(shù)和最大字符數(shù)的角標(biāo),并在超過限制后顯示警告色(默認(rèn)為紅色)。 你可以通過app:maxCharacters?(xml) 或者?setMaxCharacters()?(java) 來設(shè)置字符數(shù),通過?app:errorColor?或者?setErrorColor()(java) 來自定義警告色
app:maxCharacters="10" 設(shè)置最長文字長度10個沒超過10個字:
當(dāng)超過10個字時,效果如下:
6 自定義 error color
自定義警告顏色:
比如設(shè)置超過10個字時,顏色為綠色
<com.yh.materialeditlibrary.MaterialEditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"app:errorColor="@color/green"app:maxCharacters="10" /> ?
?
總結(jié)
以上是生活随笔為你收集整理的MaterialEditText 控件学习的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ORA-14400: inserted
- 下一篇: ubuntu 12.04及12.10无法