当前位置: 首页 > 知识库问答 >
问题:

为什么这个活动在新的Android版本中显示而不是在旧版本中显示

姬俊驰
2023-03-14

我在用Android Studio。

如何使它支持旧版本?

intractivity.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"/>
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();

    }

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

共有1个答案

湛文乐
2023-03-14

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

fonts/CircularPro-Medium.otf 

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

 类似资料:
  • 我更新了JDK 1.7_51和JRE 1.7.79。My JAVA_HOME设置为C:\Program Files\Java\JDK1.7.0_51,而JRE_HOME设置为C:\Program Files\Java\JRE7(更新79),路径指向JDK 1.7_51/bin。 为什么java版本没有指向java 7 79更新?它指向Java7更新51。理想情况下,它应该指向JRE更新79。

  • 我有一个文本视图,它有一个单行的阿拉伯语(从右到左)文本。文本内容会随着时间的推移而增加,最后一部分(最左侧)应该始终出现。水平滚动条最初设置为右侧,随着文本的增加自动向左滚动。 下面的代码在2.3Android手机上运行良好。这来自layout.xml 我在我的活动的onCreat()方法中有这个 问题在于android 4.0手机上文本视图的行为不一致。水平滚动条最初不位于右侧,因此文本视图最

  • 我已经升级我的java到jdk 1.7(1.70_71-b14

  • 在的下载站点上,它说你可以克隆它来更新它。我下载它是为了安装它,但我开始真正进入并希望从现在开始每次更新它时都克隆它。我想我找到了我们需要克隆它的地方,经过了大量的搜索和比平时更少的文档。如果我是对的,它就在目录中,就在我的眼皮底下! 我是不是没有找到难以捉摸的文件夹,还是团队直到最新版本发布后才让您直接克隆它?例如,我知道VirtualBox就是这样做的。 我知道这有点重复这个问题,但我尝试了它

  • 我是Android开发新手,所以我可能错过了一些明显的可以尝试的东西。 我试图调试一些代码,但调试器正在逐步执行旧版本的代码,而不是我项目中的当前版本。 我试过: 卸载以前安装到设备上的apk 重建/清理 使用Genymotion和真正的设备(姜饼) adb终止服务器 重新启动并重新启动。工作室 类似的问题 这实际上是cwac demo v9,所以它是一个使用“摄像头”库的演示应用程序,我正在调试

  • 我正在运行