裏面我已經開發了按鈕與中風文字泄漏的Android功能 'setTextColor'
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint.Join;
import android.graphics.Paint.Style;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.Button;
public class ButtonStrokeText extends Button
{
private int strokeColor=Color.TRANSPARENT;
private int strokeWidth=2;
public ButtonStrokeText(Context context)
{
super(context);
}
public ButtonStrokeText(Context context, AttributeSet attrs)
{
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.ButtonStrokeText);
strokeColor=a.getColor(R.styleable.ButtonStrokeText_textStrokeColor, strokeColor);
strokeWidth=a.getDimensionPixelSize(R.styleable.ButtonStrokeText_textStrokeWidth, strokeWidth);
a.recycle();
}
@Override
public void onDraw(Canvas canvas)
{
final ColorStateList textColor = getTextColors();
TextPaint paint = getPaint();
paint.setStyle(Style.STROKE);
paint.setStrokeJoin(Join.ROUND);
paint.setStrokeMiter(10);
setTextColor(strokeColor);
paint.setStrokeWidth(strokeWidth);
super.onDraw(canvas);
paint.setStyle(Style.FILL);
setTextColor(textColor);
super.onDraw(canvas);
}
}
但裏面有setTextColor(則strokeColor)泄漏。如果我評論這行活動沒有泄露,否則我有泄漏。
我的問題是,我怎樣才能避免這種泄漏?
請張貼logcat的輸出 –
請顯示setTextColor()的代碼 – Simon
setTextColor的是Android功能N從TextView的http://grepcode.com/file/ repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/widget/TextView.java#TextView.setTextColor(int) –