TextView設置最多顯示30個字符,超過部分顯示...(省略號),有人說分別設置TextView的android:signature="true",並且設置android:ellipsize="end";但是我試了,竟然成功了,供大家參考
- <TextView
- android:id="@+id/tv"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:maxEms="18"
- android:singleLine="true"
- android:ellipsize="end"
- />
TextView是經常會在listview中作數據顯示,然而像很多團購那樣,經常會有什麼爆款,打折,原價啥,一個textview就這麼被一天線強插而入。
一般情況下我們會想都不想直接在佈局文件上加那個線。但是往往效果並沒那麼好看。福利來了,通過JAVA代碼在上面加一條線。
下面看代碼:直接在文字上加一條線豈不是更好...
- StringBuffer sbf = new StringBuffer("¥"+goods.getValue());//將獲取到的商品信息存入到BUFFER裏面去
- //添加中劃線
- SpannableString spannable = new SpannableString(sbf);
- spannable.setSpan(new StrikethroughSpan(), 0, sbf.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
- holder.value.setText(spannable);//給控件賦值
-
在scrollview中會經常遇到滑動不兼容的,或者第一次進去的時候位置就混亂了,現也貼出代碼看下:
-
// 滾動條到頂部去了
mViewFlow.setFocusable(true);
mViewFlow.setFocusableInTouchMode(true);
mViewFlow.requestFocus(); - 其中的mViewFlow是指定的頂端的控件,只要切換即可
-
// 設置字符的變更
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);// 設置光標在最後
}
}
}); - 其中的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非全屏