增加对话框蒙层颜色深度
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
package com.mogo.module.extensions.weather;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.text.Layout;
|
||||
import android.text.TextPaint;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
|
||||
import com.mogo.skin.support.IMogoSkinCompatSupportable;
|
||||
import com.mogo.skin.support.helper.MogoSkinCompatTextHelperDelegate;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 带边框的textView
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class StrokeTextView extends AppCompatTextView implements IMogoSkinCompatSupportable {
|
||||
|
||||
private MogoSkinCompatTextHelperDelegate textHelperDelegate;
|
||||
|
||||
public StrokeTextView(Context context) {
|
||||
this(context,null);
|
||||
}
|
||||
|
||||
public StrokeTextView(Context context, @Nullable AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public StrokeTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
textHelperDelegate = new MogoSkinCompatTextHelperDelegate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextAppearance(Context context, int resId) {
|
||||
super.setTextAppearance(context, resId);
|
||||
textHelperDelegate.onSetTextAppearance(context, resId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int widthSize = getMeasuredWidth();
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
widthSize += 20;
|
||||
Layout mLayout = getLayout();
|
||||
if (mLayout != null) {
|
||||
mLayout.increaseWidthTo(widthSize);
|
||||
}
|
||||
setMeasuredDimension(widthSize, getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
int oriColor = getCurrentTextColor();
|
||||
// 先画边框
|
||||
TextPaint paint = getPaint();
|
||||
setCurTextColor(Color.YELLOW);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setShadowLayer(10F, 0F, 0F, Color.YELLOW);
|
||||
float b = getTextSize() / 20;
|
||||
float shadowWidth = Math.max(b, 2f);
|
||||
paint.setStrokeWidth(shadowWidth);
|
||||
super.onDraw(canvas);
|
||||
// 再画文字
|
||||
setCurTextColor(oriColor);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过反射直接设置mCurTextColor这个变量,直接调用{@link #setTextColor(int)}会出现重复递归的问题
|
||||
*
|
||||
* @param color 要设置的颜色值
|
||||
*/
|
||||
private void setCurTextColor(int color) {
|
||||
try {
|
||||
Field mCurTextColor = TextView.class.getDeclaredField("mCurTextColor");
|
||||
mCurTextColor.setAccessible(true);
|
||||
mCurTextColor.set(this,color);
|
||||
mCurTextColor.setAccessible(false);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applySkin() {
|
||||
textHelperDelegate.applySkin();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user