安卓中常用控件遇到問題解決方法(持續更新和發現篇幅)(在textview上加一條線、待續)

TextView設置最多顯示30個字符,超過部分顯示...(省略號),有人說分別設置TextView的android:signature="true",並且設置android:ellipsize="end";但是我試了,竟然成功了,供大家參考

[java] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. <TextView   
  2. android:id="@+id/tv"  
  3. android:layout_width="wrap_content"  
  4. android:layout_height="wrap_content"  
  5. android:maxEms="18"  
  6. android:singleLine="true"  
  7. android:ellipsize="end"  
  8. />  

TextView是經常會在listview中作數據顯示,然而像很多團購那樣,經常會有什麼爆款,打折,原價啥,一個textview就這麼被一天線強插而入。

一般情況下我們會想都不想直接在佈局文件上加那個線。但是往往效果並沒那麼好看。福利來了,通過JAVA代碼在上面加一條線。

下面看代碼:直接在文字上加一條線豈不是更好...

[java] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. StringBuffer sbf = new StringBuffer("¥"+goods.getValue());//將獲取到的商品信息存入到BUFFER裏面去
  2. //添加中劃線 
  3. SpannableString spannable = new SpannableString(sbf); 
  4. spannable.setSpan(new StrikethroughSpan(), 0, sbf.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
  5. holder.value.setText(spannable);//給控件賦值




在scrollview中會經常遇到滑動不兼容的,或者第一次進去的時候位置就混亂了,現也貼出代碼看下:

[java] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. // 滾動條到頂部去了
    mViewFlow.setFocusable(true);
    mViewFlow.setFocusableInTouchMode(true);
    mViewFlow.requestFocus();
  2.  其中的mViewFlow是指定的頂端的控件,只要切換即可

[java] view plaincopy在CODE上查看代碼片派生到我的代碼片
  1. // 設置字符的變更
    feedBackText.addTextChangedListener(new TextWatcher() {
    private CharSequence temp;
    private int selectionStart;
    private int selectionEnd;


    public void beforeTextChanged(CharSequence s, int start, int count,
    int after) {


    }


    public void onTextChanged(CharSequence s, int start, int before,
    int count) {
    temp = s;
    }


    public void afterTextChanged(Editable s) {
    int number = s.length();// 獲得長度
    textNum.setText("" + number + "/1000");
    selectionStart = feedBackText.getSelectionStart();
    selectionEnd = feedBackText.getSelectionEnd();
    if (temp.length() > 1000) {
    s.delete(selectionStart - 1, selectionEnd);
    int tempSelection = selectionEnd;
    feedBackText.setText(s);
    feedBackText.setSelection(tempSelection);// 設置光標在最後
    }
    }
    });
  2.  其中的mViewFlow是指定的頂端的控件,只要切換即可  當輸入框裏面的字符長度變更的時候,後面的也就跟着變更了


設置activity無標題

方法一:

在Manifest.xml中爲activity增加屬性:  android:theme="@android:style/Theme.NoTitleBar"

方法二:

在activity的onCreate()中加入:requestWindowFeature(Window.FEATURE_NO_TITLE);


2.設置activity全屏

方法一:

在Manifest.xml中爲activity增加屬性:  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"


方法二:

代碼中增加方法:

public void setFullScreen(boolean isFullScreen) {
if (isFullScreen) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}

true爲設置全屏, false非全屏





發佈了62 篇原創文章 · 獲贊 7 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章