Android實(shí)現(xiàn)文字下方加橫線
本文實(shí)例為大家分享了Android實(shí)現(xiàn)文字下方加橫線的具體代碼,供大家參考,具體內(nèi)容如下
public class WhiteTextviewWithWhiteBottomLine extends LinearLayout { private Context mContext; public WhiteTextviewWithWhiteBottomLine(Context context) { this(context, null); } public WhiteTextviewWithWhiteBottomLine(Context context, @Nullable AttributeSet attrs) { this(context, attrs, 0); } public WhiteTextviewWithWhiteBottomLine(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mContext = context; initViews(); } private TextView textView; private View viewLine; private void initViews() { View view = View.inflate(mContext, R.layout.view_textview_with_bottom_line, null); textView = view.findViewById(R.id.tv_view_textview_with_line); viewLine = view.findViewById(R.id.view_view_textview_with_line); this.addView(view); setSelected(false); } public void setTextViewText(String s) { textView.setText(s); } public void setLineColor(@ColorInt int color) { viewLine.setBackgroundColor(color); } public void setSelected(boolean isSelected) { if (isSelected) { viewLine.setVisibility(VISIBLE); } else { viewLine.setVisibility(GONE); } } public boolean isSelected() { if (viewLine.getVisibility() == View.VISIBLE) { return true; }else { return false; } } }
布局文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical"> <TextView android:id="@+id/tv_view_textview_with_line" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:padding="10dp" android:text="測(cè)試" android:textColor="@color/white" android:textSize="12sp" /> <View android:id="@+id/view_view_textview_with_line" android:layout_width="30dp" android:layout_height="1dp" android:layout_gravity="center_horizontal" android:background="@color/white" /> </LinearLayout> </LinearLayout>
如果想改變文字、線的顏色這些,直接修改布局文件中的內(nèi)容。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android8.1原生系統(tǒng)網(wǎng)絡(luò)感嘆號(hào)消除的方法
- Android開發(fā)實(shí)現(xiàn)消除屏幕鎖的方法
- Android實(shí)現(xiàn)文字動(dòng)態(tài)高亮讀取進(jìn)度效果
- Android 實(shí)現(xiàn)文字左右對(duì)齊
- Android基于AdapterViewFlipper實(shí)現(xiàn)的圖片/文字輪播動(dòng)畫控件
- Android獲取文字高度的三種方法
- Android Button按鈕點(diǎn)擊背景和文字變化操作
- Android實(shí)現(xiàn)文字滾動(dòng)播放效果的代碼
- android命令行模擬輸入事件(文字、按鍵、觸摸等)
- Android實(shí)現(xiàn)文字消除效果
相關(guān)文章
Android實(shí)現(xiàn)基本功能的新聞應(yīng)用
這篇文章主要介紹了一個(gè)簡(jiǎn)易功能的Android新聞應(yīng)用實(shí)現(xiàn)流程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-12-12android 左右滑動(dòng)+索引圖標(biāo)實(shí)現(xiàn)方法與代碼
使用Gallery和ImageView實(shí)現(xiàn)android左右滑動(dòng)+索引圖標(biāo)效果,接下來詳細(xì)介紹,有需要的朋友可以參考下2012-12-12Android實(shí)現(xiàn)滑動(dòng)側(cè)邊欄
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)滑動(dòng)側(cè)邊欄效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12Android Studio 如何刪除/新建一個(gè)module(圖文教程詳解)
這篇文章主要介紹了Android Studio 如何刪除/新建一個(gè)module,此方法也會(huì)將該module從你的硬盤中刪除,如果直接右鍵會(huì)發(fā)現(xiàn)沒有delete選項(xiàng),本文通過圖文并茂的形式給大家介紹的非常詳細(xì),需要的朋友參考下吧2020-03-03Kotlin中Stack與LinkedList的實(shí)現(xiàn)方法示例
這篇文章主要給大家介紹了關(guān)于Kotlin中Stack與LinkedList實(shí)現(xiàn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-06-06Android自定義ImageView實(shí)現(xiàn)在圖片上添加圖層效果
這篇文章給大家主要介紹了利用Android自定義ImageView如何實(shí)現(xiàn)在圖片上添加圖層的效果,實(shí)現(xiàn)的效果類似在圖片增加秒殺、搶光等標(biāo)簽圖片,對(duì)大家開發(fā)的時(shí)候具有一定的參考借鑒價(jià)值,有需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧。2016-11-11Android UI控件ExpandableListView基本用法詳解
這篇文章主要為大家詳細(xì)介紹了Android UI控件ExpandableListView基本用法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09