5

Như bạn đã biết Vector Drawables đã được thêm vào Thư viện hỗ trợ Android 23.2 được công bố trong Android Developer Blog cho tất cả các phiên bản android chúng ta có thể sử dụng nó thay vì thêm các biểu tượng khác kích cỡ. Tuy nhiên tùy chọn "bật tự động phản chiếu cho bố cục RTL" không hoạt động trong các phiên bản Android dưới 6.0! Có cài đặt bổ sung nào để sử dụng nó trong các phiên bản Android khác không?Tự động phản chiếu cho bố cục RTL không hoạt động trong các phiên bản Android dưới 6.0

enter image description here

Dự án thử nghiệm của tôi sử dụng một phương pháp đơn giản để thay đổi Locale của ứng dụng của tôi. Đây là những kết quả thử nghiệm của tôi:

Nexus 6P với Android 6.0 mà làm việc tốt đẹp:

enter image description here enter image description here

Nexus 7 với Android 5.0:

enter image description here enter image description here

Cảm ơn

+0

bất kỳ câu trả lời xin vui lòng? –

+0

@mostafahashim Thật không may, có vẻ như tính năng này không hỗ trợ trong phiên bản Android dưới 6.0. Tôi sử dụng 'mipmap' khác trong thư mục' mipmap' và 'mipmap-ldrtl' cho mỗi biểu tượng phải theo Local. Đối với các biểu tượng khác, tôi sử dụng 'VectorDrawable'. – Nava

Trả lời

0

Bug Báo cáo: link

Lật vector drawable nếu địa phương là arabic và drawable là auto gương

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; 
} 
0

bạn có thể sử dụng tạo ImageView tùy chỉnh và nếu xoay persian 180.

Các vấn đề liên quan