android:shadowColor="#000000" android:shadowDx="0" android:shadowDy="-2" android:shadowRadius="0.1"
android:includeFontPadding="false"
android:singleLine="true" android:focusable="true" android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forever"
((TextView) findViewById(R.id.test)).getPaint().setFakeBoldText(true);
首先建立res\color文件夹,然后创建textview_colors_selector.xml文件,内容如下:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:color="#3399FF"/> <item android:state_focused="true" android:color="#3399FF"/> <item android:state_pressed="true" android:color="#3399FF"/> <item android:color="#FFFFFF"></item> </selector>
<TextView android:clickable="true" android:text="点击我会变颜色的哦!" android:textColor="@color/textview_colors_selector" android:textSize="24sp" />
如果这里需求是点击 Button 上文字变色时,只需以下代码
Button btn=(Button)findViewById(R.id.btn); Resources resource=(Resources)getBaseContext().getResources(); ColorStateList csl=(ColorStateList)resource.getColorStateList(R.color.textview_colors_selector); if(csl!=null){ btn.setTextColor(color_state_list);//设置按钮文字颜色 }
<TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="end" android:maxLines="2" />
private boolean openState = false; if(!openState){ //展开显示全部 tv.setSingleLine(openState); tv.setEllipsize(null); openState = true; btn.setText("收缩"); }else{ // tv.setSingleLine(openState); tv.setMaxLines(2); tv.setEllipsize(TruncateAt.END); openState = false; btn.setText("展开"); }