给textview获得焦点时加边框背景

这是一个跑马灯的textview

 

tv = new TextView(this);

tv.setWidth(150);

tv.setBackgroundResource(R.drawable.tvfocusbg);

tv.setClickable(true);

tv.setFocusableInTouchMode(true);

tv.setSingleLine(true);

tv.setEllipsize(TruncateAt.MARQUEE);

tv.setMarqueeRepeatLimit(3);

tv.setText(p.pName);

 

边框背景tvfocusbg定义如下:

 

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_focused="true">

<shape>

<solid android:color="@android:color/transparent"/>

<stroke android:width="1dp" android:color="#dcdcdc" />

<corners android:radius="2dp" />

<padding android:left="2dp" android:top="2dp"

android:right="2dp" android:bottom="2dp" />

</shape>

</item>

</selector>

 

 

你可能感兴趣的:(android,encoding)