gpt4 book ai didi

java - 为什么此 Activity 显示在新的Android版本中而不显示在旧版本中

转载 作者:行者123 更新时间:2023-12-02 09:38:03 34 4
gpt4 key购买 nike

我正在使用Android Studio。

仅适用于Android 9

在Android 8和7上无法正常工作

问题来自使用@SuppressLint(“ AppCompatCustomView”)//我们不需要在BRButton.java中支持较早版本

如何使它支持较旧的版本?

E / FirebaseCrash:未启用Firebase崩溃报告
E / AndroidRuntime:致命异常:main
        流程:com.loafwallet,PID:6085
        java.lang.RuntimeException:无法启动活动ComponentInfo {com.loafwallet / com.breadwallet.presenter.activities.intro.IntroActivity}:android.view.InflateException:二进制XML文件行#23:二进制XML文件行#23:错误膨胀类com.breadwallet.presenter.customviews.BRButton
            在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
            在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
            在android.app.ActivityThread.-wrap12(ActivityThread.java)
            在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460)
            在android.os.Handler.dispatchMessage(Handler.java:102)
            在android.os.Looper.loop(Looper.java:154)
            在android.app.ActivityThread.main(ActivityThread.java:6077)
            在java.lang.reflect.Method.invoke(本机方法)
            在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:866)
            在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
         原因:android.view.InflateException:二进制XML文件第23行:二进制XML文件第23行:膨胀类com.breadwallet.presenter.customviews.BRButton时出错
         原因:android.view.InflateException:二进制XML文件第23行:膨胀类com.breadwallet.presenter.customviews.BRButton时出错
         引起原因:java.lang.reflect.InvocationTargetException
            在java.lang.reflect.Constructor.newInstance0(本机方法)
            在java.lang.reflect.Constructor.newInstance(Constructor.java:430)
            在android.view.LayoutInflater.createView(LayoutInflater.java:645)
            在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
            在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
            在android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
            在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
            在android.view.LayoutInflater.inflate(LayoutInflater.java:518)
            在android.view.LayoutInflater.inflate(LayoutInflater.java:426)
            在android.view.LayoutInflater.inflate(LayoutInflater.java:377)
            在com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:414)
            在android.app.Activity.setContentView(Activity.java:2414)
            在com.breadwallet.presenter.activities.intro.IntroActivity.onCreate(IntroActivity.java:84)
            在android.app.Activity.performCreate(Activity.java:6662)
            在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
            在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
            在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
            在android.app.ActivityThread.-wrap12(ActivityThread.java)
            在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460)
            在android.os.Handler.dispatchMessage(Handler.java:102)
            在android.os.Looper.loop(Looper.java:154)
            在android.app.ActivityThread.main(ActivityThread.java:6077)
            在java.lang.reflect.Method.invoke(本机方法)
            在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:866)
            在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
         引起原因:java.lang.RuntimeException:找不到字体资产fonts / CircularPro-Medium.otf
            在android.graphics.Typeface.createFromAsset(Typeface.java:206)
            在com.breadwallet.tools.manager.FontManager.get(FontManager.java:55)
            在com.breadwallet.tools.manager.FontManager.setCustomFont(FontManager.java:67)
            在com.breadwallet.presenter.customviews.BRButton.init(BRButton.java:100)
            在com.breadwallet.presenter.customviews.BRButton。(BRButton.java:79)
            在java.lang.reflect.Constructor.newInstance0(本机方法)
            在java.lang.reflect.Constructor.newInstance(Constructor.java:430)
            在android.view.LayoutInflater.createView(LayoutInflater.java:645)
            在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
            在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
            在android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
            在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
            在android.view.LayoutInflater.inflate(LayoutInflater.java:518)
            在android.view.LayoutInflater.inflate(LayoutInflater.java:426)
            在android.view.LayoutInflater.inflate(LayoutInflater.java:377)
            在com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:414)
            在android.app.Activity.setContentView(Activity.java:2414)
            在com.breadwallet.presenter.activities.intro.IntroActivity.onCreate(IntroActivity.java:84)
            在android.app.Activity.performCreate(Activity.java:6662)
            在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
            在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
            在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
            在android.app.ActivityThread.-wrap12(ActivityThread.java)
            在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460)
            在android.os.Handler.dispatchMessage(Handler.java:102)
            在android.os.Looper.loop(Looper.java:154)
            在android.app.ActivityThread.main(ActivityThread.java:6077)
            在java.lang.reflect.Method.invoke(本机方法)
            在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:866)
            在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
    E / FirebaseInstanceId:令牌检索失败:SERVICE_NOT_AVAILABLE
    E / FirebaseInstanceId:令牌检索失败:SERVICE_NOT_AVAILABLE
    E / FirebaseInstanceId:令牌检索失败:SERVICE_NOT_AVAILABLE
    申请已终止。

IntroActivity.xml




<ImageView
android:id="@+id/BRText"
android:layout_width="128dp"
android:layout_height="64dp"
android:layout_marginTop="96dp"
android:src="@drawable/ctlx_logo"

app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"/>

<com.breadwallet.presenter.customviews.BRButton
android:id="@+id/button_new_wallet"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="@dimen/bread_margin"
android:layout_marginStart="@dimen/bread_margin"
app:buttonType="1"
android:padding="10dp"
android:text="@string/MenuViewController.createButton"
android:textColor="@color/white"
android:background="@android:color/transparent"
android:textSize="18sp"
app:isBreadButton="true"
app:layout_constraintBottom_toTopOf="@+id/button_recover_wallet"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

<com.breadwallet.presenter.customviews.BRButton
android:id="@+id/button_recover_wallet"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginBottom="32dp"
android:background="@android:color/transparent"
android:layout_marginEnd="@dimen/bread_margin"
android:layout_marginStart="@dimen/bread_margin"
app:buttonType="2"
android:padding="10dp"
android:text="@string/RecoverWallet.header"
android:textColor="@color/button_secondary_text"
android:textSize="18sp"
app:isBreadButton="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

<com.breadwallet.presenter.customviews.BRText
android:id="@+id/textView7"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:lineSpacingMultiplier="1.3"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="@dimen/bread_margin"
android:text="@string/StartViewController.message"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="@dimen/header"
app:customTFont="CircularPro-Book.otf"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/BRText"/>

<ImageButton
android:id="@+id/faq_button"
android:layout_width="@dimen/faq_dimen"
android:layout_height="@dimen/faq_dimen"
android:layout_marginEnd="@dimen/bread_margin"
android:layout_marginTop="@dimen/bread_margin"
android:background="@drawable/faq_question_white"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

<View
android:id="@+id/splash_screen"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="0dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_marginTop="0dp"
android:background="@drawable/bread_gradient"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"/>




IntroActivity.java

public static final Point screenParametersPoint = new Point();

@Override
protected void onRestart() {
super.onRestart(); // Always call the superclass method first
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
newWalletButton = (Button) findViewById(R.id.button_new_wallet);
recoverWalletButton = (Button) findViewById(R.id.button_recover_wallet);
splashScreen = findViewById(R.id.splash_screen);
setListeners();
updateBundles();
faq = (ImageButton) findViewById(R.id.faq_button);

faq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
BRAnimator.showSupportFragment(app, BRConstants.startView);
}
});

if (!BuildConfig.DEBUG && BRKeyStore.AUTH_DURATION_SEC != 300) {
Log.e(TAG, "onCreate: BRKeyStore.AUTH_DURATION_SEC != 300");
BRReportsManager.reportBug(new RuntimeException("AUTH_DURATION_SEC should be 300"), true);
}
introActivity = this;

getWindowManager().getDefaultDisplay().getSize(screenParametersPoint);

if (Utils.isEmulatorOrDebug(this))
Utils.printPhoneSpecs();

byte[] masterPubKey = BRKeyStore.getMasterPublicKey(this);
boolean isFirstAddressCorrect = false;
if (masterPubKey != null && masterPubKey.length != 0) {
isFirstAddressCorrect = SmartValidator.checkFirstAddress(this, masterPubKey);
}
if (!isFirstAddressCorrect) {
BRWalletManager.getInstance().wipeWalletButKeystore(this);
}

PostAuth.getInstance().onCanaryCheck(this, false);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
splashScreen.setVisibility(View.GONE);
}
}, 1000);

}

private void updateBundles() {
BRExecutor.getInstance().forBackgroundTasks().execute(new Runnable() {
@Override
public void run() {
Thread.currentThread().setName("updateBundle");
final long startTime = System.currentTimeMillis();
APIClient apiClient = APIClient.getInstance(IntroActivity.this);
apiClient.updateBundle();
long endTime = System.currentTimeMillis();
Log.d(TAG, "updateBundle DONE in " + (endTime - startTime) + "ms");
}
});
}


private void setListeners() {
newWalletButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
BreadActivity bApp = BreadActivity.getApp();
if (bApp != null) bApp.finish();
Intent intent = new Intent(IntroActivity.this, SetPinActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);
}
});

recoverWalletButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!BRAnimator.isClickAllowed()) return;
BreadActivity bApp = BreadActivity.getApp();
if (bApp != null) bApp.finish();
Intent intent = new Intent(IntroActivity.this, RecoverActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);
}
});
}

@Override
protected void onResume() {
super.onResume();
appVisible = true;
app = this;

}

@Override
protected void onPause() {
super.onPause();
appVisible = false;
}

@Override
protected void onSaveInstanceState(Bundle outState) {

}

@Override
protected void onStop() {
super.onStop();
}


@Override
public void onBackPressed() {
super.onBackPressed();

}

}


BRButton.java

@SuppressLint("AppCompatCustomView") 
public class BRButton extends Button {
private static final String TAG = BRButton.class.getName();
private static int ANIMATION_DURATION = 30;
private Bitmap shadow;
private Rect shadowRect;
private RectF bRect;
private int width;
private int height;
private int modifiedWidth;
private int modifiedHeight;
private Paint bPaint;
private Paint bPaintStroke;
private int type = 2;
private static final float SHADOW_PRESSED = 0.88f;
private static final float SHADOW_UNPRESSED = 0.95f;
private float shadowOffSet = SHADOW_UNPRESSED;
private static final int ROUND_PIXELS = 16;
private boolean isBreadButton;

public BRButton(Context context) {
super(context);
init(context, null);
}

public BRButton(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}

public BRButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}

public BRButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}

private void init(Context ctx, AttributeSet attrs) {
shadow = BitmapFactory.decodeResource(getResources(), R.drawable.shadow);
bPaint = new Paint();
bPaintStroke = new Paint();
shadowRect = new Rect(0, 0, 100, 100);
bRect = new RectF(0, 0, 100, 100);
TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.BRButton);
String customFont = a.getString(R.styleable.BRButton_customBFont);
FontManager.setCustomFont(ctx, this, Utils.isNullOrEmpty(customFont) ? "CircularPro-Medium.otf" : customFont);
float px16 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, getResources().getDisplayMetrics());
//check attributes you need, for example all paddings
int[] attributes = new int[]{android.R.attr.paddingStart, android.R.attr.paddingTop, android.R.attr.paddingEnd, android.R.attr.paddingBottom, R.attr.isBreadButton, R.attr.buttonType};
TypedArray arr = ctx.obtainStyledAttributes(attrs, attributes);

isBreadButton = a.getBoolean(R.styleable.BRButton_isBreadButton, false);
int paddingLeft = arr.hasValue(0) ? arr.getDimensionPixelOffset(0, -1) : (int) px16;
int paddingTop = arr.hasValue(1) ? arr.getDimensionPixelOffset(1, -1) : 0;
int paddingRight = arr.hasValue(2) ? arr.getDimensionPixelOffset(2, -1) : (int) px16;
int paddingBottom = arr.hasValue(3) ? arr.getDimensionPixelOffset(3, -1) + (isBreadButton ? (int) px16 : 0) : (isBreadButton ? (int) px16 : 0);

int type = a.getInteger(R.styleable.BRButton_buttonType, 0);
setType(type);

bPaint.setAntiAlias(true);
bPaintStroke.setAntiAlias(true);

if (isBreadButton) {
setBackground(getContext().getDrawable(R.drawable.shadow_trans));
}

setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
a.recycle();
arr.recycle();
final ViewTreeObserver observer = getViewTreeObserver();
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (observer.isAlive()) {
observer.removeOnGlobalLayoutListener(this);
}
correctTextSizeIfNeeded();
correctTextBalance();
}
});
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (isBreadButton) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(false);
}
if (type != 3)
press(ANIMATION_DURATION);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
unPress(ANIMATION_DURATION);
}
}

return super.onTouchEvent(event);

}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
width = w;
height = h;

}

private void correctTextSizeIfNeeded() {
int limit = 100;
int lines = getLineCount();
float px = getTextSize();
while (lines > 1 && !getText().toString().contains("\n")) {
limit--;
px -= 1;
setTextSize(TypedValue.COMPLEX_UNIT_PX, px);
lines = getLineCount();
if (limit <= 0) {
Log.e(TAG, "correctTextSizeIfNeeded: Failed to rescale, limit reached, final: " + px);
break;
}
}
}

private void correctTextBalance() {

}

@Override
protected void onDraw(Canvas canvas) {
if (isBreadButton) {
shadowRect.set(5, height / 4, width - 5, (int) (height * shadowOffSet));
modifiedWidth = width - 10;
modifiedHeight = height - height / 4 - 5;
bRect.set(5, 5, modifiedWidth, modifiedHeight + 5);
canvas.drawBitmap(shadow, null, shadowRect, null);
canvas.drawRoundRect(bRect, ROUND_PIXELS, ROUND_PIXELS, bPaint);
if (type == 2 || type == 3)
canvas.drawRoundRect(bRect, ROUND_PIXELS, ROUND_PIXELS, bPaintStroke);
}
super.onDraw(canvas);

}

public void setType(int type) {
if (type == 3) press(1);
this.type = type;

if (type == 1) { //blue
bPaint.setColor(getContext().getColor(R.color.button_primary_normal));
setTextColor(getContext().getColor(R.color.white));
} else if (type == 2) { //gray stroke
bPaintStroke.setColor(getContext().getColor(R.color.extra_light_gray));
bPaintStroke.setStyle(Paint.Style.STROKE);
bPaintStroke.setStrokeWidth(Utils.getPixelsFromDps(getContext(), 1));
setTextColor(getContext().getColor(R.color.light_gray));
bPaint.setColor(getContext().getColor(R.color.button_secondary));
bPaint.setStyle(Paint.Style.FILL);
} else if (type == 3) { //blue strokeww
bPaintStroke.setColor(getContext().getColor(R.color.button_primary_normal));
bPaintStroke.setStyle(Paint.Style.STROKE);
bPaintStroke.setStrokeWidth(Utils.getPixelsFromDps(getContext(), 1));
setTextColor(getContext().getColor(R.color.button_primary_normal));
bPaint.setColor(getContext().getColor(R.color.button_secondary));
bPaint.setStyle(Paint.Style.FILL);
}
invalidate();
}

private void press(int duration) {
ScaleAnimation scaleAnim = new ScaleAnimation(
1f, 0.96f,
1f, 0.96f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 1f);
scaleAnim.setDuration(duration);
scaleAnim.setRepeatCount(0);
scaleAnim.setInterpolator(new AccelerateDecelerateInterpolator());
scaleAnim.setFillAfter(true);
scaleAnim.setFillBefore(true);
scaleAnim.setFillEnabled(true);

ValueAnimator shadowAnim = ValueAnimator.ofFloat(SHADOW_UNPRESSED, SHADOW_PRESSED);
shadowAnim.setDuration(duration);
shadowAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
shadowOffSet = (float) animation.getAnimatedValue();
invalidate();
}
});

startAnimation(scaleAnim);
shadowAnim.start();

}

private void unPress(int duration) {
ScaleAnimation scaleAnim = new ScaleAnimation(
0.96f, 1f,
0.96f, 1f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 1f);
scaleAnim.setDuration(duration);
scaleAnim.setRepeatCount(0);
scaleAnim.setInterpolator(new AccelerateDecelerateInterpolator());``
scaleAnim.setFillAfter(true);
scaleAnim.setFillBefore(true);
scaleAnim.setFillEnabled(true);

ValueAnimator shadowAnim = ValueAnimator.ofFloat(SHADOW_PRESSED, SHADOW_UNPRESSED);
shadowAnim.setDuration(duration);
shadowAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
shadowOffSet = (float) animation.getAnimatedValue();
invalidate();
}
});

startAnimation(scaleAnim);
shadowAnim.start();
}
}

最佳答案

错误只是说Android Studio无法找到以下资产文件

fonts/CircularPro-Medium.otf 


确认文件存在于资产目录内的字体文件夹中,然后重新生成项目。

关于java - 为什么此 Activity 显示在新的Android版本中而不显示在旧版本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57334946/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com