「Update」

1、修复 未兼容控件导致的崩溃异常
2、增加 getRawInputStream 获取资源包下的Raw文件流
This commit is contained in:
donghongyu
2024-10-14 16:31:34 +08:00
parent 3df5db5dbe
commit 4bc66d0387
3 changed files with 59 additions and 19 deletions

View File

@@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* donghongyu
* donghongyu
*/
public class SkinAttribute {
@@ -76,8 +76,9 @@ public class SkinAttribute {
} else {
try {
// @12343455332
if (isNumeric(attributeValue.substring(1))) {
resId = Integer.parseInt(attributeValue.substring(1));
String resIdStr = attributeValue.substring(1);
if (isNumeric(resIdStr)) {
resId = Integer.parseInt(resIdStr);
}
} catch (Exception e) {
// 由于有时候TextView会直接配置文字而不是用 @string/XXX 所以会导致这里转换异常,车里简单的处理异常跳过即可
@@ -130,7 +131,8 @@ public class SkinAttribute {
* @param typeface 字体
*/
public void applySkin(Typeface typeface) {
applySkinTypeface(typeface);
Log.d(TAG, "applySkin() called with: typeface = [" + typeface + "] view = [" + view + "] Parent = " + view.getParent());
//applySkinTypeface(typeface);
applySkinViewSupport();
try {
for (SkinPair skinPair : skinPairs) {
@@ -147,20 +149,32 @@ public class SkinAttribute {
}
break;
case "src":
if (view instanceof ImageView){
background = SkinResources.getInstance().getBackground(skinPair.resId);
if (background instanceof Integer) {
((ImageView) view).setImageDrawable(new ColorDrawable((Integer) background));
} else {
((ImageView) view).setImageDrawable((Drawable) background);
try {
if (view instanceof ImageView) {
background = SkinResources.getInstance().getBackground(skinPair.resId);
if (background instanceof Integer) {
((ImageView) view).setImageDrawable(new ColorDrawable((Integer) background));
} else {
((ImageView) view).setImageDrawable((Drawable) background);
}
}
} catch (Exception e) {
e.printStackTrace();
}
break;
case "textColor":
((TextView) view).setTextColor(SkinResources.getInstance().getColorStateList(skinPair.resId));
try {
((TextView) view).setTextColor(SkinResources.getInstance().getColorStateList(skinPair.resId));
} catch (Exception e) {
e.printStackTrace();
}
break;
case "textColorHint":
((EditText) view).setHintTextColor(SkinResources.getInstance().getColorStateList(skinPair.resId));
try {
((EditText) view).setHintTextColor(SkinResources.getInstance().getColorStateList(skinPair.resId));
} catch (Exception e) {
e.printStackTrace();
}
break;
case "drawableLeft":
left = SkinResources.getInstance().getDrawable(skinPair.resId);
@@ -179,12 +193,16 @@ public class SkinAttribute {
applySkinTypeface(typeface1);
break;
case "text":
textStr = SkinResources.getInstance().getString(skinPair.resId);
applyText(textStr);
if (skinPair.resId > 0) {
textStr = SkinResources.getInstance().getString(skinPair.resId);
applyText(textStr);
}
break;
case "hint":
textStr = SkinResources.getInstance().getString(skinPair.resId);
applyHintText(textStr);
if (skinPair.resId > 0) {
textStr = SkinResources.getInstance().getString(skinPair.resId);
applyHintText(textStr);
}
break;
default:
break;