Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.content.res.Configuration; import android.graphics.drawable.Drawable; import android.os.Build; import android.view.View; import android.widget.TextView; public class Main { /** * @see android.widget.TextView#setCompoundDrawablesRelative(Drawable, Drawable, Drawable, * Drawable) */ public static void setCompoundDrawablesRelative(TextView textView, Drawable start, Drawable top, Drawable end, Drawable bottom) { if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1) { // On JB MR1, due to a platform bug, setCompoundDrawablesRelative() is a no-op if the // view has ever been measured. As a workaround, use setCompoundDrawables() directly. // See: http://crbug.com/368196 and http://crbug.com/361709 boolean isRtl = isLayoutRtl(textView); textView.setCompoundDrawables(isRtl ? end : start, top, isRtl ? start : end, bottom); } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setCompoundDrawablesRelative(start, top, end, bottom); } else { textView.setCompoundDrawables(start, top, end, bottom); } } /** * Returns true if view's layout direction is right-to-left. * * @param view the View whose layout is being considered */ public static boolean isLayoutRtl(View view) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { return view.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; } else { // All layouts are LTR before JB MR1. return false; } } /** * @see Configuration#getLayoutDirection() */ public static int getLayoutDirection(Configuration configuration) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { return configuration.getLayoutDirection(); } else { // All layouts are LTR before JB MR1. return View.LAYOUT_DIRECTION_LTR; } } }