天天看點

Android小提示二

@ TOC

【27.EditText軟鍵盤】

EditText初始不彈出軟鍵盤,隻有光标顯示,點選再彈出

解決方法1:

在清單activity屬性中設定

android:windowSoftInputMode="stateHidden"           

解決方法2:

InputMethodManager inputMethodManager = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(et.getWindowToken(), 0);           

解決方法3:

系統預設第一個EditText是獲得焦點的,解決辦法,增加一個不顯示的view強制獲得焦點,比如

<View 
android:layout_width="0dip"
android:layout_height="0dip"
android:focusableInTouchMode="true" />           

【隐藏軟鍵盤-未驗證】

// * 隐藏軟體盤
public void hideSoftInput() {
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    if (getCurrentFocus() != null) {
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    }
}
 
// * 點選軟鍵盤之外的空白處,隐藏軟體盤
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        View v = getCurrentFocus();
        if (ToolUtil.isShouldHideInput(v, ev)) {
 
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
            }
        }
        return super.dispatchTouchEvent(ev);
    }
    // 必不可少,否則所有的元件都不會有TouchEvent了
    if (getWindow().superDispatchTouchEvent(ev)) {
        return true;
    }
    return onTouchEvent(ev);
}
 
// * 顯示軟鍵盤
public void showInputMethod(){
    if (getCurrentFocus() != null){
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        imm.showSoftInputFromInputMethod(getCurrentFocus().getWindowToken(),0);
    }
}           

【軟鍵盤不遮擋輸入框】

https://blog.csdn.net/u012523122/article/details/52101303/
方法一:在你的activity中的oncreate中setContentView之前寫上這個代碼
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

方法二:在項目的AndroidManifest.xml檔案中界面對應的裡加入
android:windowSoftInputMode="stateVisible|adjustResize"
這樣會讓螢幕整體上移。
如果加上的 是 android:windowSoftInputMode="adjustPan"這樣鍵盤就會覆寫螢幕。

各值的含義:
stateUnspecified:軟鍵盤的狀态并沒有指定,系統将選擇一個合适的狀态或依賴于主題的設定
stateUnchanged:當這個activity出現時,軟鍵盤将一直保持在上一個activity裡的狀态,無論是隐藏還是顯示
stateHidden:使用者選擇activity時,軟鍵盤總是被隐藏
stateAlwaysHidden:當該Activity主視窗擷取焦點時,軟鍵盤也總是被隐藏的
stateVisible:軟鍵盤通常是可見的
stateAlwaysVisible:使用者選擇activity時,軟鍵盤總是顯示的狀态
adjustUnspecified:預設設定,通常由系統自行決定是隐藏還是顯示
adjustResize:該Activity總是調整螢幕的大小以便留出軟鍵盤的空間
adjustPan:目前視窗的内容将自動移動以便目前焦點從不被鍵盤覆寫和使用者能總是看到輸入内容的部分

方法三:(用的此處)
把頂級的layout替換成ScrollView,或者說在頂級的Layout上面再加一層ScrollView。
這樣就會把軟鍵盤和輸入框一起滾動了,軟鍵盤會一直處于底部。
一般頂級View需要加上 android:fitsSystemWindows="true"           

【28.定時器】(注意不是延時器)

1.Handler類的postDelayed方法:

Handler mHandler = new Handler();
Runnable r = new Runnable() {
    @Override
    public void run() {
        //do something
        //每隔1s循環執行run方法
        mHandler.postDelayed(this, 1000);
    }
};
主線程中調用:  mHandler.postDelayed(r, 100);//延時100毫秒           

2.用handler+timer+timeTask方法:

Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 1){
                //do something
            }
            super.handleMessage(msg);
        }
};

Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
            Message message = new Message();
            message.what = 1;
            handler.sendMessage(message);
        }
};
主線程中調用:timer.schedule(timerTask,1000,500);//延時1s,每隔500毫秒執行一次run方法           

3.Thread+handler方法:

Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.what == 1){
                //do something
            }
            super.handleMessage(msg);
        }
};

class MyThread extends Thread {//這裡也可用Runnable接口實作
        @Override
        public void run() {
            while (true){
                try {
                    Thread.sleep(1000);//每隔1s執行一次
                    Message msg = new Message();
                    msg.what = 1;
                    handler.sendMessage(msg);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
}
主線程中調用:new Thread(new MyThread()).start();           

【29.延時器】

1.Handler的postDelayed方法:

new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
              //do something
          }
}, 1000);    //延時1s執行           

2.timer + TimerTask方法:

Timer timer = new Timer();
timer.schedule(new TimerTask() {                   
      @Override
      public void run() {
              //do something
      }
},1000);//延時1s執行           

3.Thread方法:

new Thread(new MyThread()).start();
//或
new Thread(new Runnable() {
    @Override
    public void run() {
        try {
            Thread.sleep(1000);//延時1s
            //do something
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}).start();           

【30.TextView 上下滑動 左右滑動設定】

1.垂直滑動

android:scrollbars = "vertical"           

2.水準滑動

android:scrollbars = "horizontal"
  android:scrollbars="none" //不顯示滾動條           

必須在Java添加(否則無法滑動)

ArrowKeyMovementMethod.getInstance()  //水準
  tx.setMovementMethod(ScrollingMovementMethod.getInstance());  /垂直           

要加:android:ellipsize="none"

android:singleLine="true"

3.設定滾動條一直存在

android:fadeScrollbars="false"           

4.自定義滾動條屬性

android:scrollbarThumbVertical="@drawable/bar"           

5.跑馬燈:

android:singleLine="true"
android:ellipsize="marquee"           
https://blog.csdn.net/beiminglei/article/details/9317997
//設定字元寬度(其實em是一個印刷排版的機關,表示字寬的機關)為10,
//一般一個漢字為一個寬度,
android:maxEms="10"  
//值為1-5時,m = n..
6-11時,m = n+1。
12-18時,m = n+2。           

【31.防止快速點選】

private static long lastClick = 0;
private boolean fastClick() {
    if (System.currentTimeMillis() - lastClick <= 1000) {
        return false;
    }
    lastClick = System.currentTimeMillis();
    return true;
}           

【32.EditText 輸入内容】

代碼中
//InputType.TYPE_NUMBER_FLAG_DECIMAL 的代碼是8192,而我們需要的是8194就是android:inputType="numberDecimal",
 //但是沒有這個常量,是以我們需要手動的輸入數字
editText.setInputType(8194);

android:digits="1234567890."   ====  editText.setInputType(EditorInfo.TYPE_CLASS_PHONE); 

InputType.TYPE_CLASS_NUMBER    數字類型 1234567890
InputType.TYPE_CLASS_DATETIME  日期類型 1234567890/-
//自定義digits(https://www.jianshu.com/p/691b00e750c7)
editText.setKeyListener(DigitsKeyListener.getInstance("0123456789-"));           
android:inputType="none"--輸入普通字元
android:inputType="text"--輸入普通字元
android:inputType="textCapCharacters"--輸入普通字元
android:inputType="textCapWords"--單詞首字母大小
android:inputType="textCapSentences"--僅第一個字母大小
android:inputType="textAutoCorrect"--前兩個自動完成
android:inputType="textAutoComplete"--前兩個自動完成
android:inputType="textMultiLine"--多行輸入
android:inputType="textImeMultiLine"--輸入法多行(不一定支援)
android:inputType="textNoSuggestions"--不提示
android:inputType="textUri"--URI格式
android:inputType="textEmailAddress"--電子郵件位址格式
android:inputType="textEmailSubject"--郵件主題格式
android:inputType="textShortMessage"--短消息格式
android:inputType="textLongMessage"--長消息格式
android:inputType="textPersonName"--人名格式
android:inputType="textPostalAddress"--郵政格式
android:inputType="textPassword"--密碼格式
android:inputType="textVisiblePassword"--密碼可見格式
android:inputType="textWebEditText"--作為網頁表單的文本格式
android:inputType="textFilter"--文本篩選格式
android:inputType="textPhonetic"--拼音輸入格式
android:inputType="number"--數字格式
android:inputType="numberSigned"--有符号數字格式
android:inputType="numberDecimal"--可以帶小數點的浮點格式
android:inputType="phone"--撥号鍵盤
android:inputType="datetime"
android:inputType="date"--日期鍵盤
android:inputType="time"--時間鍵盤           

EditText有預設高度直接設定setHeight沒作用。

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
        DensityUtil.dip2px(context, 25));
layoutParams.setMargins(0, 0, 0, 0);
editText.setIncludeFontPadding(false);//去除内邊距
//最大輸入長度
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)}); //最大輸入長度
【kotlin版:editText.filters = arrayOf(InputFilter.LengthFilter(24))】
editText.setInputType(InputType.TYPE_CLASS_NUMBER); //數字輸入類型
editText.setTextColor(context.getResources().getColor(R.color.color_888888));
editText.setPadding(10, 0, 0, 1);//否則文字顯示不全
editText.setLayoutParams(layoutParams);//這有這樣才能設定寬高,否則預設高度80(有内邊距)/75
editText.setBackground(null); //去除下劃線及所有格式           

樣式:

android:background="@null"//光标的樣式沒有改變,下劃線消失了,邊距也沒有了           

遊标樣式

<EditText
    android:text=" "//初始遊标向後移動一個機關
    android:textCursorDrawable="@drawable/color_cursor"//設定遊标寬度和顔色

将textCursorDrawable設定為@null,表示去除系統預設的樣式
隐藏光标的屬性是android:cursorVisible,光标的顔色是跟文字android:textColor保持一緻

sendText.setSelection(sendText.getText().length()); //遊标在最後
sendText.setSelection(0, sendText.getText().length()); //選中全部内容           

下劃線修改樣式:[

https://www.jb51.net/article/121010.htm

]()

//用的此
<style name="MyEditText" parent="Theme.AppCompat.Light"> 
 <item name="colorControlNormal">@color/indigo</item> //控件預設的顔色
 <item name="colorControlActivated">@color/pink</item>//控件被激活時的顔色
</style>

<EditText 
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:hint="Hint text"
android:theme="@style/MyEditText"/>           
Android小提示二
//其他
et_underline_unselected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item
          android:bottom="0dp"
          android:left="-2dp"
          android:right="-2dp"
          android:top="-2dp">
              <shape>
                   <solid android:color="@android:color/transparent" />
                   <stroke
                        android:width="1dp"
                        android:color="@android:color/darker_gray" />
                   <padding android:bottom="4dp" />
              </shape>
     </item>
</layer-list>

et_underline_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item
          android:bottom="0dp"
          android:left="-2dp"
          android:right="-2dp"
          android:top="-2dp">
              <shape>
                   <solid android:color="@android:color/transparent" />
                   <stroke
                        android:color="@android:color/holo_green_light"
                        android:width="2dp" />
                   <padding android:bottom="4dp" />
              </shape>
     </item>
</layer-list>

//第一種:
<EditText
      android:id="@+id/editText1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="3dp"
      android:background="@null"
      android:hint="自定義EditText下劃線1"
      android:textCursorDrawable="@drawable/cursor_color" />
      
/**初始化EditText,預設都為未選中狀态**/
editText1.setBackgroundResource(R.drawable.et_underline_unselected);

/**第一個EditText的焦點監聽事件**/
editText1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
     @Override
     public void onFocusChange(View v, boolean hasFocus) {
          if (hasFocus) {
           Log.e(TAG, "EditText1獲得焦點");
           editText1.setBackgroundResource(R.drawable.et_underline_selected);
          } else {
           Log.e(TAG, "EditText1失去焦點");
           editText1.setBackgroundResource(R.drawable.et_underline_unselected);
          }
     }
});

//第二種
et_underline_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_focused="false" android:drawable="@drawable/et_underline_unselected"/>
     <item android:state_focused="true" android:drawable="@drawable/et_underline_selected"/>
</selector>

<EditText
      android:id="@+id/editText1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="3dp"
      android:background="@drawable/et_underline_selector"
      android:hint="自定義EditText下劃線1"
      android:textCursorDrawable="@drawable/cursor_color" />
      
cursor_color.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="rectangle">
     <size android:width="2dp" />
     <solid android:color="@android:color/holo_blue_light" />
</shape>           

【33.AndroidBase64加解密】

Android項目引用不到以下兩個java類

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;           

Android有自己的base64類

import android.util.Base64

String str = "Hello!";  
//base64編碼  
//String strBase64 = new String(Base64.encode(str.getBytes(), Base64.DEFAULT));  
String strBase64 = Base64.encodeToString(str.getBytes(), Base64.DEFAULT);  
//base64解碼  
String str2 = new String(Base64.decode(strBase64.getBytes(), Base64.DEFAULT));           

【34.Java中字元串拼接-删除最後一個字元】

str.split("\|"); //轉義字元

StringBuilder builder = new StringBuilder();
for (int i = 0; i < 5; i++) {
    builder.append("aaa").append(",");
}
System.out.println(builder.toString());

if (builder.length() <= 0) {
    return;
}
//或者 String 用equals ===與上面length判段一樣
if ("".contentEquals(time)) {
    return;
}

String aaa = builder.substring(0, builder.length() - 1);
System.out.println(aaa);

//1.deleteCharAt
builder = builder.deleteCharAt(builder.length() - 1);
System.out.println(builder.toString());

//2.【用的這個】如果沒有,則傳回-1
builder = builder.deleteCharAt(builder.lastIndexOf(","));
System.out.println(builder);

//3.setLength
builder.setLength(builder.length() - 1);
System.out.println(builder);

//Java8的内置一個新的StringJoiner
StringJoiner joiner = new StringJoiner(",");
for (int i = 0; i < 5; i++) {
    joiner.add("bbb");
}
System.out.println(joiner);

//其他-在前面添加分隔符,然後删除
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 5; i++) {
    sb.append(",").append(i);
}
sb = sb.deleteCharAt(0);
System.out.println(sb);

//輸出
原始:aaa,aaa,aaa,aaa,aaa,
substring:aaa,aaa,aaa,aaa,aaa
deleteCharAt + length:aaa,aaa,aaa,aaa,aaa  //注意
deleteCharAt + lastIndexOf:aaa,aaa,aaa,aaaaaa //注意我這裡是指派給原始builder
setLength:aaa,aaa,aaa,aaaaa //注意我這裡是指派給原始builder
Joiner:bbb,bbb,bbb,bbb,bbb
字首:0,1,2,3,4           

【JS中字元串截取】

var str = 'Hello World!';
str=str.slice(0,str.length-1)  //方式一(可以負數):Hello World
str=str.substr(0,str.length-1) //方式二(可以負數):Hello World
str=str.substring(0,str.length-1)//方式三(不能負數):Hello World
str=str.substring(0, str.lastIndexOf('!'));  

str = str.substr(1); //删除第一個字元 ello World!           

【35.日期字元串比較大小】

//第一種直接用字元串類的compareTo方法:
public static boolean compareNowDate1(String t1, String t2) {
    int result = t1.compareTo(t2);
    //result>0 則t1>t2;
    //result<=0 則t1<=t2
    return result > 0;
}

//第二種是把這個日期字元串轉換成long:
public static boolean compareNowDate1(String t1, String t2) {
    SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
    try {
        Date d1 = format.parse(t1);
        Date d2 = format.parse(t2);
        long result = d1.getTime() - d2.getTime();
        //result>=0 則value大于等于now
        //result<0 則value小于now
        return result > 0;
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return false;
}

//第三種是把日期字元串轉換成整形int:
public static boolean compareNowDate1(String t1, String t2) {
    //可以try catch
    int int1 = Integer.parseInt(t1);
    int int2 = Integer.parseInt(t2);
    int result = int1 - int2;
    //result>=0 則value大于等于now
    //result<0 則value小于now
    return result > 0;
}           

【番外:删除git賬号】

[生成公鑰:ssh-keygen -t rsa -c "[email protected]"]三次回車

git 提取項目Authentication failed 和Incorrect username or password ( access token )的問題

接着怎麼提取,都是這樣,也不是會再次提示輸入賬号和密碼;

解決辦法:

1.控制台進入使用者賬戶

2.點選管理windows憑據

Android小提示二

【36.隐藏App界面及圖示】

<application
    ...
    android:theme="@android:style/Theme.NoDisplay">
    
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    
            <category android:name="android.intent.category.LAUNCHER" />
            <!--無啟動頁面-->
            <data
                android:host=".app"
                android:pathPrefix="/openwith"
                android:scheme="myapp" />
        </intent-filter>
    </activity>
</application>               
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    android:theme="@android:style/Theme.NoDisplay">

</LinearLayout>

//無啟動頁面
//setContentView(R.layout.activity_main)           

【39.繪制view寬高】

[

https://blog.csdn.net/chenbaige/article/details/77991594

在activity中擷取view 的尺寸大小(寬度和高度),若隻寫getWidth()、getHeight()等方法是擷取不到View的寬度和高度大小的

疑問解答: 實際情況下,View的measure過程和Activity的生命周期方法不是同步執行的,是以無法保證Activity在執行完某個生命周期方法時View已經測量完畢了,這種情況下,擷取到的尺寸大小就是0。

//1.Activity的 onWindowFocusChanged方法中擷取: 
//onWindowFocusChanged方法執行時代表View已經初始化完畢了,寬度和高度已經測量完畢并且最終确認好了,
//onWindowFocusChanged會執行多次,在Activity擷取焦點和失去焦點時都會被調用一次。
// 即在onPause和onResume方法被執行時被反複調用。
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        int width = bbb.getMeasuredWidth();
        int height = bbb.getMeasuredHeight();
        ZLog.e("1.view寬:" + width + "  view高:" + height);
    }
}

//2.View.post方法
//當執行到這個runable方法的時候,View所有的初始化測量方法說明都已經執行完畢了。
view.post(new Runnable() {
    @Override
    public void run() {
        int width = bbb.getMeasuredWidth();
        int height = bbb.getMeasuredHeight();
        ZLog.e("2.view寬:" + width + "  view高:" + height);
    }
});

//3.ViewTreeObserver
//當View樹的狀态發生改變或者View樹内部View的可見性發生改變的時候,onGlobalLayout将會被回調。
//注意:伴随着View樹的狀态改變,onGlobalLayout會被調用多次。
ViewTreeObserver observer = view.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
        view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        int width = view.getMeasuredWidth();
        int height = view.getMeasuredHeight();
        ZLog.e("3.view寬:" + width + "  view高:" + height);
        aaa.setMaxWidth(widthP - width - 10);//遲到了,aaa已經超過了這時width=0
    }
});

//4.measure
//手動調用measure後,View會調用onMeasure方法對View發起測量,測量完後,就可以擷取測量後的寬度和高度了。
//但是要對LayoutParams的參數分情況處理才能得到具體的參數值:
//4.1) View的LayoutParams參數為match_parent:
    //這種情況下無法擷取到具體寬高值,因為當View的測量模式為match_parent時,寬高值是取父容器的剩餘空間大小作為它自己的寬高。
    //而這時無法擷取到父容器的尺寸大小,是以擷取會失敗。
//4.2) View的LayoutParams參數為具體值:(為0??)
int widthV = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.EXACTLY);
int heigtV = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.EXACTLY);
bbb.measure(widthV, heigtV);
int width1 = bbb.getMeasuredWidth();
int height1 = bbb.getMeasuredHeight();
ZLog.e("4.view寬:" + width1 + "  view高:" + height1);

//4.3) wrap_content:可以用
int width22 = View.MeasureSpec.makeMeasureSpec((1 << 30) - 1, View.MeasureSpec.AT_MOST);
int height22 = View.MeasureSpec.makeMeasureSpec((1 << 30) - 1, View.MeasureSpec.AT_MOST);
bbb.measure(width22, height22);
int height222 = bbb.getMeasuredHeight();
int width222 = bbb.getMeasuredWidth();
ZLog.e("5.view寬:" + width222 + "  view高:" + height222);
//aaa.setMaxWidth(widthP - width222 - 10);

【我用的此】
//(可以用)注意:View.MeasureSpec.UNSPECIFIED
//4.1當TextView的屬性是wrap_content時,如何擷取其寬度,特别是在界面還沒顯示時,比如像在RecycleView中的情況
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
bbb.measure(spec, spec);
int width11 = bbb.getMeasuredWidth();
int height11 = bbb.getMeasuredHeight();
ZLog.e("4.1 view寬:" + width11 + "  view高:" + height11);           

【40.基本類型轉字元串】

float+“”這個有個+号,是在常量池裡操作的,會生成兩個。是以

String.valueOf(float)相對好一點。

另外:+與StringBuider的對比 [

https://mp.weixin.qq.com/s/dc7HW0SqEcJknMIqoQZnlg

【41.TextView變色】

https://weilu.blog.csdn.net/article/details/52863741
text.setText(Html.fromHtml("商品編碼<font color=red>*</font>:"));
text.setText(Html.fromHtml(String.format("商品編碼<font color=red>*</font>:%s","22")));
//注意:html傳回的是Spanned不是字元串,他繼承CharSequence
//HTML的一些其他:https://blog.csdn.net/baidu_34012226/article/details/53301047

//2種:https://www.jianshu.com/p/f004300c6920 包括設定大小
SpannableStringBuilder builder = new SpannableStringBuilder(bar_code);
int index = bar_code.indexOf(etScan);
builder.setSpan(new ForegroundColorSpan(Color.RED), index,
        index + etScan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(builder);

//連結形式
android:autoLink 設定是否當文本為URL連結/email/号碼/map時,文本顯示為可點選的連結。
可選值:none/web/Email/phone/map/all

android:lineSpacingExtra="8dp"  //是行間距,他預設是0,是一個絕對高度值。
lineSpacingMultiplier屬性,它代表行間距倍數,預設為1.0f,是一個相對高度值。
android:text="攬件方式:上門取件\n快遞公司:順豐快遞"           

【42.限制EditText輸入的小數的位數】

①xml中限制輸入的類型:

android:inputType="numberDecimal"           

②重寫InputFilter

public class DecimalDigitsInputFilter implements InputFilter {

    private final int decimalDigits;

    public DecimalDigitsInputFilter(int digits) {
        this.decimalDigits = digits;
    }

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        // source:目前輸入的字元
        // start:輸入字元的開始位置
        // end:輸入字元的結束位置
        // dest:目前已顯示的内容
        // dstart:目前光标開始位置
        // dent:目前光标結束位置
        //Log.e("", "source=" + source + ",start=" + start + ",end=" + end + ",dest=" + dest.toString() + ",dstart=" + dstart + ",dend=" + dend);
        if (dest.length() == 0 && source.equals(".")) {
            return "0.";
        }
        String dValue = dest.toString();
        String[] splitArray = dValue.split("\\.");
        if (splitArray.length > 1) {
            String dotValue = splitArray[1];
            //輸入框小數的位數是 decimalDigits 的情況時小數位不可以輸入,整數位可以正常輸入
            if (dotValue.length() == decimalDigits && dest.length() - dstart <= decimalDigits) {
                return "";
            }
        }
        return null;
    }
}           

③設定小數點位數,這裡傳進去的是2位

edit.setFilters(new InputFilter[]{new DecimalDigitsInputFilter(2)});           

【TextView代碼設定展開與省略】

//TextView代碼設定展開與省略
textView.setOnClickListener(v -> {
    if (isShowDes) {
        textView.setEllipsize(TextUtils.TruncateAt.END);
        textView.setSingleLine();
    } else {
        textView.setEllipsize(null);
        textView.setSingleLine(false);
    }
    isShowDes = !isShowDes;
});