fix: 修复透明主题异常

This commit is contained in:
HuanChengFly 2020-11-14 15:48:55 +08:00
parent ceab9ae853
commit 129b9e7056
7 changed files with 72 additions and 10 deletions

View File

@ -0,0 +1,7 @@
package com.huanchengfly.tieba.post.interfaces
interface BackgroundTintable {
fun setBackgroundTintResId(resId: Int)
fun getBackgroundTintResId(): Int
}

View File

@ -32,6 +32,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.huanchengfly.tieba.post.BaseApplication;
import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.activities.BaseActivity;
import com.huanchengfly.tieba.post.interfaces.BackgroundTintable;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.widgets.theme.TintSwipeRefreshLayout;
import com.scwang.smart.refresh.header.MaterialHeader;
@ -281,6 +282,9 @@ public class ThemeUtil {
}
}
view.setBackgroundTintList(null);
if (view instanceof BackgroundTintable) {
((BackgroundTintable) view).setBackgroundTintResId(0);
}
String backgroundFilePath = SharedPreferencesUtil.get(BaseApplication.getInstance(), SharedPreferencesUtil.SP_SETTINGS)
.getString(SP_TRANSLUCENT_THEME_BACKGROUND_PATH, null);
if (backgroundFilePath == null) {
@ -329,7 +333,7 @@ public class ThemeUtil {
}
public static void setTranslucentThemeBackground(View view) {
setTranslucentThemeBackground(view, true, true);
setTranslucentThemeBackground(view, true, false);
}
@StyleRes

View File

@ -10,12 +10,13 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.interfaces.BackgroundTintable;
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.R;
@SuppressLint("CustomViewStyleable")
public class TintConstraintLayout extends ConstraintLayout implements Tintable {
public class TintConstraintLayout extends ConstraintLayout implements Tintable, BackgroundTintable {
private int mBackgroundTintResId;
public TintConstraintLayout(@NonNull Context context) {
@ -57,10 +58,12 @@ public class TintConstraintLayout extends ConstraintLayout implements Tintable {
}
}
@Override
public int getBackgroundTintResId() {
return mBackgroundTintResId;
}
@Override
public void setBackgroundTintResId(int backgroundTintResId) {
mBackgroundTintResId = backgroundTintResId;
tint();

View File

@ -10,12 +10,13 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.interfaces.BackgroundTintable;
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.R;
@SuppressLint("CustomViewStyleable")
public class TintCoordinatorLayout extends CoordinatorLayout implements Tintable {
public class TintCoordinatorLayout extends CoordinatorLayout implements Tintable, BackgroundTintable {
private int mBackgroundTintResId;
public TintCoordinatorLayout(@NonNull Context context) {
@ -56,4 +57,15 @@ public class TintCoordinatorLayout extends CoordinatorLayout implements Tintable
}
}
}
@Override
public void setBackgroundTintResId(int resId) {
mBackgroundTintResId = resId;
tint();
}
@Override
public int getBackgroundTintResId() {
return mBackgroundTintResId;
}
}

View File

@ -10,12 +10,13 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.interfaces.BackgroundTintable;
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.R;
@SuppressLint("CustomViewStyleable")
public class TintFrameLayout extends FrameLayout implements Tintable {
public class TintFrameLayout extends FrameLayout implements Tintable, BackgroundTintable {
private int mBackgroundTintResId;
public TintFrameLayout(@NonNull Context context) {
@ -56,4 +57,15 @@ public class TintFrameLayout extends FrameLayout implements Tintable {
}
}
}
@Override
public void setBackgroundTintResId(int resId) {
mBackgroundTintResId = resId;
tint();
}
@Override
public int getBackgroundTintResId() {
return mBackgroundTintResId;
}
}

View File

@ -10,12 +10,13 @@ import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.interfaces.BackgroundTintable;
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
import com.huanchengfly.tieba.post.R;
@SuppressLint("CustomViewStyleable")
public class TintLinearLayout extends LinearLayout implements Tintable {
public class TintLinearLayout extends LinearLayout implements Tintable, BackgroundTintable {
private int mBackgroundTintResId;
public TintLinearLayout(@NonNull Context context) {
@ -56,4 +57,15 @@ public class TintLinearLayout extends LinearLayout implements Tintable {
}
}
}
@Override
public void setBackgroundTintResId(int resId) {
mBackgroundTintResId = resId;
tint();
}
@Override
public int getBackgroundTintResId() {
return mBackgroundTintResId;
}
}

View File

@ -12,11 +12,12 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.interfaces.BackgroundTintable;
import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable;
import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils;
@SuppressLint("CustomViewStyleable")
public class TintRelativeLayout extends RelativeLayout implements Tintable {
public class TintRelativeLayout extends RelativeLayout implements Tintable, BackgroundTintable {
private int mBackgroundTintResId;
public TintRelativeLayout(@NonNull Context context) {
@ -63,4 +64,15 @@ public class TintRelativeLayout extends RelativeLayout implements Tintable {
super.setBackground(background);
applyTintColor();
}
@Override
public void setBackgroundTintResId(int resId) {
mBackgroundTintResId = resId;
tint();
}
@Override
public int getBackgroundTintResId() {
return mBackgroundTintResId;
}
}