增加对话框蒙层颜色深度

This commit is contained in:
tongchenfei
2020-11-24 17:28:28 +08:00
parent d982d19598
commit 7301b59527
6 changed files with 118 additions and 3 deletions

1
.idea/gradle.xml generated
View File

@@ -77,6 +77,7 @@
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>

View File

@@ -3,5 +3,5 @@
<color name="module_authorize_loading_text">#99FFFFFF</color>
<color name="module_authorize_text">#FFFFFF</color>
<color name="module_authorize_affirm_text">#FFFFFF</color>
<color name="module_authorize_color">#7F000000</color>
<color name="module_authorize_color">#99000000</color>
</resources>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="module_commons_dlg_bkg">#7f000000</color>
<color name="module_commons_dlg_bkg">#99000000</color>
<color name="module_commons_wm_dialog_text_textColor">#FFFFFF</color>
<color name="v2x_FFF_666">#FFFFFF</color>
<color name="module_commons_FFF_333">#FFFFFF</color>

View File

@@ -5,7 +5,7 @@
<item name="android:windowFrame">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimAmount">0.4</item>
<item name="android:backgroundDimAmount">0.6</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:fullBright">@android:color/transparent</item>

View File

@@ -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();
}
}

View File

@@ -291,4 +291,17 @@
android:visibility="gone"
app:constraint_referenced_ids="btnShowDrawableTipNoSize,btnShowDrawableTip,btnShowTextTip,btnDebugCtrlNaviView,btnDebugCtrlSubView,btnDebugCtrlTopView,btnDebugAddBottomLayerView" />
<com.mogo.module.extensions.weather.StrokeTextView
android:id="@+id/stTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
android:gravity="center"
android:text="1234"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:textColor="@color/module_ext_weather_text_color"
android:visibility="gone"/>
</androidx.constraintlayout.widget.ConstraintLayout>