国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android實現(xiàn)EditText添加下劃線

2019-10-21 21:40:07
字體:
供稿:網(wǎng)友

在安卓高版本,默認(rèn)是有下劃線的,其默認(rèn)下劃線的顏色是由其主題顏色來控制的! 

控制如下:

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">    <!-- Customize your theme here. -->    <item name="colorPrimary">@color/colorPrimary</item>    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>    **<item name="colorAccent">@color/colorPrimaryDark</item>**

所以,只需要修改colorAccent的顏色,其下劃線的顏色既可以修改!

在低版本和高版本中,同樣是可以去添加下劃線的!方法有二: 

方法一:

//此時必須要設(shè)置其背景為空<EditText    android:background="@null"    android:drawableBottom="@drawable/line"    android:hint="請輸入您的手機(jī)號碼"    android:layout_width="match_parent"    android:layout_height="wrap_content"/>
//資源名稱為 drawable/line<shape xmlns:android="http://schemas.android.com/apk/res/android">  <solid android:color="@color/colorBlue" />  <size    android:height="1dp"    android:width="1000dp" /></shape>

方法二:通過自定義editText

public class UnderLineEditText extends EditText {  private Paint paint;  public UnderLineEditText(Context context, AttributeSet attrs) {    super(context, attrs);    //設(shè)置畫筆的屬性    paint = new Paint();    paint.setStyle(Paint.Style.STROKE);    //設(shè)置畫筆顏色為紅色    paint.setColor(Color.RED);  }  @Override  protected void onDraw(Canvas canvas) {    super.onDraw(canvas);    /**canvas畫直線,從左下角到右下角,this.getHeight()-2是獲得父edittext的高度,但是必須要-2這樣才能保證     * 畫的橫線在edittext上面,和原來的下劃線的重合     */    canvas.drawLine(0, this.getHeight()-2, this.getWidth()-2, this.getHeight()-2, paint);  }}

這里有幾點需要注意: 

其一:也可以繼承android.support.v7.widget.AppCompatEditText,但是有時會出現(xiàn)獲取不到焦點的現(xiàn)狀 

其二:下劃線的的位置確定

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 杭锦后旗| 安泽县| 东港市| 金塔县| 涪陵区| 高邮市| 东乡| 吉首市| 蒲江县| 澜沧| 军事| 拉萨市| 岳池县| 庆元县| 潍坊市| 闻喜县| 平果县| 集贤县| 兴海县| 从化市| 南陵县| 化德县| 呼伦贝尔市| 长白| 区。| 靖安县| 钦州市| 庄浪县| 衡阳市| 北票市| 仁寿县| 鲁甸县| 肇源县| 龙州县| 衢州市| 金溪县| 同江市| 左贡县| 阳城县| 海伦市| 新野县|