Android 改变背景可拉深的安卓磨损

Android 改变背景可拉深的安卓磨损,android,wear-os,ambient,Android,Wear Os,Ambient,我想问一下,当android wear处于环境模式时,您将如何更改背景可绘制 这是我的密码 public void draw(Canvas canvas, Rect bounds,Context context) { time.setToNow(); // canvas.drawColor(Color.parseColor("#e91e63")); int width = bounds.width(); int height = bounds.height();

我想问一下,当android wear处于环境模式时,您将如何更改背景可绘制

这是我的密码

 public void draw(Canvas canvas, Rect bounds,Context context) {
    time.setToNow();
   // canvas.drawColor(Color.parseColor("#e91e63"));

    int width = bounds.width();
    int height = bounds.height();
    Resources resources = context.getResources();

    if (shouldShowAmbient) {
        backgroundDrawable = resources.getDrawable(R.drawable.ambient_domo);
    } else {
        backgroundDrawable = resources.getDrawable(R.drawable.domo);
    }

    mBackgroundBitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
    // Draw the background, scaled to fit.
    if (mBackgroundScaledBitmap == null
            || mBackgroundScaledBitmap.getWidth() != width
            || mBackgroundScaledBitmap.getHeight() != height) {
        mBackgroundScaledBitmap = Bitmap.createScaledBitmap(mBackgroundBitmap,
                width, height, true /* filter */);
    }
    canvas.drawBitmap(mBackgroundScaledBitmap, 0, 0, null);
    String timeText = String.format(shouldShowSeconds ? TIME_FORMAT_WITH_SECONDS : TIME_FORMAT_WITHOUT_SECONDS, time.hour, time.minute, time.second);
    float timeXOffset = computeXOffset(timeText, timePaint, bounds);
    float timeYOffset = computeTimeYOffset(timeText, timePaint, bounds);
    canvas.drawText(timeText, timeXOffset, timeYOffset, timePaint);

    String dateText = String.format(DATE_FORMAT, time.monthDay, (time.month + 1), time.year);
    float dateXOffset = computeXOffset(dateText, datePaint, bounds);
    float dateYOffset = computeDateYOffset(dateText, datePaint);
    canvas.drawText(dateText, dateXOffset, timeYOffset + dateYOffset, datePaint);




}
下面是如何调用该方法

 @Override
    public void onAmbientModeChanged(boolean inAmbientMode) {
        super.onAmbientModeChanged(inAmbientMode);
        watchFace.setAntiAlias(!inAmbientMode);
        watchFace.setColor(Color.WHITE);
        watchFace.showAmbient(inAmbientMode);
        watchFace.setShowSeconds(false);
        invalidate();

        startTimerIfNecessary();
    }

它总是以可绘制的交互模式绘制。我不知道为什么它没有改变

我知道我们在谈论这些台词:

if (shouldShowAmbient) {
    backgroundDrawable = resources.getDrawable(R.drawable.ambient_domo);
} else {
    backgroundDrawable = resources.getDrawable(R.drawable.domo);
}
您使用了shouldShowAmbient字段,但它似乎没有设置在任何位置。WatchFaceService。引擎已经启动。你应该在这种情况下使用它