@Test public void testCompoundDrawablesRelative() throws Throwable { final Drawable drawableStart = new ColorDrawable(0xFFFF0000); drawableStart.setBounds(0, 0, 20, 20); final Drawable drawableTop = new ColorDrawable(0xFF00FF00); drawableTop.setBounds(0, 0, 30, 25); final Drawable drawableEnd = new ColorDrawable(0xFF0000FF); drawableEnd.setBounds(0, 0, 25, 20); onView(withId(R.id.text_view)).perform(setText(R.string.test_text_medium)); onView(withId(R.id.text_view)).perform(setCompoundDrawablesRelative(drawableStart, drawableTop, drawableEnd, null)); final Drawable[] drawablesAbsolute = mTextView.getCompoundDrawables(); assertEquals("Compound drawable: left", drawablesAbsolute[0], drawableStart); assertEquals("Compound drawable: left width", drawablesAbsolute[0].getBounds().width(), 20); assertEquals("Compound drawable: left height", drawablesAbsolute[0].getBounds().height(), 20); assertEquals("Compound drawable: top", drawablesAbsolute[1], drawableTop); assertEquals("Compound drawable: top width", drawablesAbsolute[1].getBounds().width(), 30); assertEquals("Compound drawable: top height", drawablesAbsolute[1].getBounds().height(), 25); assertEquals("Compound drawable: right", drawablesAbsolute[2], drawableEnd); assertEquals("Compound drawable: right width", drawablesAbsolute[2].getBounds().width(), 25); assertEquals("Compound drawable: right height", drawablesAbsolute[2].getBounds().height(), 20); assertNull("Compound drawable: bottom", drawablesAbsolute[3]); }
public static void setCompoundDrawablesRelative(@NonNull TextView textView, @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) { if (Build.VERSION.SDK_INT >= 18) { textView.setCompoundDrawablesRelative(start, top, end, bottom); } else if (Build.VERSION.SDK_INT >= 17) { boolean rtl = textView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; textView.setCompoundDrawables(rtl ? end : start, top, rtl ? start : end, bottom); } else { textView.setCompoundDrawables(start, top, end, bottom); } }
TextViewCompat { public static void setCompoundDrawablesRelative(@NonNull TextView textView, @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) { if (Build.VERSION.SDK_INT >= 18) { textView.setCompoundDrawablesRelative(start, top, end, bottom); } else if (Build.VERSION.SDK_INT >= 17) { boolean rtl = textView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; textView.setCompoundDrawables(rtl ? end : start, top, rtl ? start : end, bottom); } else { textView.setCompoundDrawables(start, top, end, bottom); } } }
TextViewCompat { public static void setCompoundDrawablesRelative(@NonNull TextView textView, @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) { if (Build.VERSION.SDK_INT >= 18) { textView.setCompoundDrawablesRelative(start, top, end, bottom); } else if (Build.VERSION.SDK_INT >= 17) { boolean rtl = textView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; textView.setCompoundDrawables(rtl ? end : start, top, rtl ? start : end, bottom); } else { textView.setCompoundDrawables(start, top, end, bottom); } } private  TextViewCompat(); }
TextViewCompat { public static void setCompoundDrawablesRelative(@NonNull TextView textView, @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) { if (Build.VERSION.SDK_INT >= 18) { textView.setCompoundDrawablesRelative(start, top, end, bottom); } else if (Build.VERSION.SDK_INT >= 17) { boolean rtl = textView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; textView.setCompoundDrawables(rtl ? end : start, top, rtl ? start : end, bottom); } else { textView.setCompoundDrawables(start, top, end, bottom); } } private  TextViewCompat(); static void setCompoundDrawablesRelative(@NonNull TextView textView,
            @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end,
            @Nullable Drawable bottom); static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView,
            @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end,
            @Nullable Drawable bottom); static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView,
            @DrawableRes int start, @DrawableRes int top, @DrawableRes int end,
            @DrawableRes int bottom); static int getMaxLines(@NonNull TextView textView); static int getMinLines(@NonNull TextView textView); static void setTextAppearance(@NonNull TextView textView, @StyleRes int resId); @NonNull static Drawable[] getCompoundDrawablesRelative(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeWithDefaults(@NonNull TextView textView,
            int autoSizeTextType); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeUniformWithConfiguration(
            @NonNull TextView textView,
            int autoSizeMinTextSize,
            int autoSizeMaxTextSize,
            int autoSizeStepGranularity,
            int unit); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeUniformWithPresetSizes(@NonNull TextView textView,
            @NonNull int[] presetSizes, int unit); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeTextType(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeStepGranularity(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeMinTextSize(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeMaxTextSize(@NonNull TextView textView); @NonNull @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int[] getAutoSizeTextAvailableSizes(@NonNull TextView textView); static void setCustomSelectionActionModeCallback(@NonNull final TextView textView,
                @NonNull final ActionMode.Callback callback); static void setFirstBaselineToTopHeight(
            @NonNull final TextView textView,
            @Px @IntRange(from = 0) final int firstBaselineToTopHeight); static void setLastBaselineToBottomHeight(
            @NonNull final TextView textView,
            @Px @IntRange(from = 0) int lastBaselineToBottomHeight); static int getFirstBaselineToTopHeight(@NonNull final TextView textView); static int getLastBaselineToBottomHeight(@NonNull final TextView textView); static void setLineHeight(@NonNull final TextView textView,
                              @Px @IntRange(from = 0) int lineHeight); }
TextViewCompat { public static void setCompoundDrawablesRelative(@NonNull TextView textView, @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, @Nullable Drawable bottom) { if (Build.VERSION.SDK_INT >= 18) { textView.setCompoundDrawablesRelative(start, top, end, bottom); } else if (Build.VERSION.SDK_INT >= 17) { boolean rtl = textView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; textView.setCompoundDrawables(rtl ? end : start, top, rtl ? start : end, bottom); } else { textView.setCompoundDrawables(start, top, end, bottom); } } private  TextViewCompat(); static void setCompoundDrawablesRelative(@NonNull TextView textView,
            @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end,
            @Nullable Drawable bottom); static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView,
            @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end,
            @Nullable Drawable bottom); static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView,
            @DrawableRes int start, @DrawableRes int top, @DrawableRes int end,
            @DrawableRes int bottom); static int getMaxLines(@NonNull TextView textView); static int getMinLines(@NonNull TextView textView); static void setTextAppearance(@NonNull TextView textView, @StyleRes int resId); @NonNull static Drawable[] getCompoundDrawablesRelative(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeWithDefaults(@NonNull TextView textView,
            int autoSizeTextType); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeUniformWithConfiguration(
            @NonNull TextView textView,
            int autoSizeMinTextSize,
            int autoSizeMaxTextSize,
            int autoSizeStepGranularity,
            int unit); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeUniformWithPresetSizes(@NonNull TextView textView,
            @NonNull int[] presetSizes, int unit); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeTextType(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeStepGranularity(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeMinTextSize(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeMaxTextSize(@NonNull TextView textView); @NonNull @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int[] getAutoSizeTextAvailableSizes(@NonNull TextView textView); static void setCustomSelectionActionModeCallback(@NonNull final TextView textView,
                @NonNull final ActionMode.Callback callback); static void setFirstBaselineToTopHeight(
            @NonNull final TextView textView,
            @Px @IntRange(from = 0) final int firstBaselineToTopHeight); static void setLastBaselineToBottomHeight(
            @NonNull final TextView textView,
            @Px @IntRange(from = 0) int lastBaselineToBottomHeight); static int getFirstBaselineToTopHeight(@NonNull final TextView textView); static int getLastBaselineToBottomHeight(@NonNull final TextView textView); static void setLineHeight(@NonNull final TextView textView,
                              @Px @IntRange(from = 0) int lineHeight); static final int AUTO_SIZE_TEXT_TYPE_NONE; static final int AUTO_SIZE_TEXT_TYPE_UNIFORM; }