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非全屏