gpt4 book ai didi

android - RTL 布局的自动镜像在低于 6.0 的 Android 版本中不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:23:08 26 4
gpt4 key购买 nike

如您所知,在 Android Developer Blog 中宣布的 Android 支持库 23.2 中添加了 Vector Drawables。对于所有版本的 android,我们都可以使用它而不是添加不同大小的额外图标。但是,“为 RTL 布局启用自动镜像”选项在 6.0 以下的 android 版本中不起作用!是否有任何其他设置可以在其他 Android 版本中使用它?

enter image description here

我的测试项目使用一种简单的方法来更改我的应用程序的语言环境。这些是我的测试结果:

Android 6.0 的 Nexus 6P 运行良好:

enter image description here enter image description here

搭载 Android 5.0 的 Nexus 7:

enter image description here enter image description here

谢谢

最佳答案

错误报告:link

如果本地为阿拉伯语且可绘制对象为自动镜像,则翻转矢量可绘制对象

public static Drawable getDrawableLocale(Activity activity, @DrawableRes int drawableResId) {
if (!Util.isRTL() || !ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_back_white, null).isAutoMirrored())
return ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_back_white, null);
/**
* Flip it for RTl because Kitkat doesn't flip
*/
Bitmap bitmap = Util.getBitmapFromVectorDrawable(activity, drawableResId);
Matrix matrix = new Matrix();
matrix.preScale(-1.0f, 1.0f);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
return new BitmapDrawable(activity.getResources(), bitmap);
}

public static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) {
Drawable drawable = getVectorDrawable(context, drawableId);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}

Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);

return bitmap;
}
public static Drawable getVectorDrawable(Context context, @DrawableRes int idVectorDrawable) {
return AppCompatDrawableManager.get().getDrawable(context, idVectorDrawable);
}


public static boolean isRTL() {
return isRTL(Locale.getDefault());
}
public static boolean isRTL(Locale locale) {
final int directionality = Character.getDirectionality(locale.getDisplayName().charAt(0));
return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
}

关于android - RTL 布局的自动镜像在低于 6.0 的 Android 版本中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38702131/

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