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

洪澤網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、響應(yīng)式網(wǎng)站等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)于2013年開始到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(liá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="請輸入您的手機號碼"
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í)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
當(dāng)前標題:Android實現(xiàn)EditText添加下劃線
鏈接分享:http://www.chinadenli.net/article0/gcceio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、全網(wǎng)營銷推廣、關(guān)鍵詞優(yōu)化、網(wǎng)頁設(shè)計公司、建站公司、手機網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)