第一:獲取 textview判斷是否有省略號
方法一:getlineCount() 返回值爲0
Layout l = location.getLayout();
if ( l!= null){
int lines = location.getLineCount();
Log.v(TAG, "location有幾行"+lines);
if ( lines > 1)
contentLayout.setOrientation(LinearLayout. VERTICAL);
}
方法二:可用,但是textview有省略號,getlineCount() 也是返回 1
location.post(new Runnable() {
@Override
public void run() {
Log.v(TAG,"當前"+location.getLineCount());
}
});
方法三:可用,textview有省略號,getlineCount() 也是返回 1;l.getEllipsisCount(lines-1) > 0 可以判斷是否有省略號
ViewTreeObserver vto = location.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Layout l = location.getLayout();
if ( l != null){
int lines = l.getLineCount();
Log.v(TAG, "最後一個方法location有幾行"+lines);
if ( lines > 0)
if ( l.getEllipsisCount(lines-1) > 0)
/* 判斷有省略號後的動作*/
contentLayout.setOrientation(LinearLayout. VERTICAL);
}
}
});
第二:代碼動態改變文字顏色
textview.setTextColor(this.getResources().getColor(R.color.white));
第三:代碼改變TextView背景顏色
qianyan_layout.setBackgroundResource(R.color.tab_top_bg);