最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2018年08月24日 16:56:13   作者:星辰之力  
這篇文章主要為大家詳細(xì)介紹了Android如何實(shí)現(xiàn)給EditText添加下劃線,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

控制如下:

 <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í)必須要設(shè)置其背景為空
<EditText
    android:background="@null"
    android:drawableBottom="@drawable/line"
    android:hint="請(qǐng)輸入您的手機(jī)號(hào)碼"
    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>

方法二:通過(guò)自定義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上面,和原來(lái)的下劃線的重合
     */
    canvas.drawLine(0, this.getHeight()-2, this.getWidth()-2, this.getHeight()-2, paint);
  }
}

這里有幾點(diǎn)需要注意:

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

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

科尔| 黔江区| 兰州市| 九寨沟县| 苍溪县| 嫩江县| 临沧市| 灵宝市| 洮南市| 绿春县| 鹤岗市| 观塘区| 固安县| 新宁县| 宣威市| 乃东县| 南平市| 镇宁| 离岛区| 鸡西市| 易门县| 巩义市| 徐州市| 海口市| 栖霞市| 靖安县| 阿瓦提县| 莫力| 达日县| 阿拉尔市| 蒲城县| 宜章县| 通化县| 徐州市| 准格尔旗| 五华县| 简阳市| 嘉定区| 绥德县| 武平县| 衡阳县|