MaterialButton drawableLeft программно не отображается без setBounds - PullRequest
0 голосов
/ 14 апреля 2019

У меня есть следующий код для программной установки drawableLeft

  public void updateActionButton() {
    int size = (int) (buttonAction.getTextSize() * 1.75);
    if (drawableNext == null) {
        drawableNext = ContextCompat.getDrawable(getActivity(), R.drawable.ic_arrow_right_white_48dp);
        drawableInfo = ContextCompat.getDrawable(getActivity(), R.drawable.ic_information_white_48dp);
        drawableNext.setBounds(0, 0, size, size);
        drawableInfo.setBounds(0, 0, size, size);
    }
    Drawable leftDrawable, rightDrawable;
    if (next) {
        buttonAction.setText(R.string.next);
        rightDrawable = drawableNext;
        leftDrawable = null;
    } else {
        leftDrawable = drawableInfo;
        rightDrawable = null;
    }
    buttonAction.setCompoundDrawables(leftDrawable, null, rightDrawable, null);
}

Где buttonAction - это MaterialButton, и эта тема устанавливается (если я не использую это, MaterialButton вызывает сбой приложения)

<style name="AppTheme" parent="Theme.MaterialComponents.Light">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/colorBackground</item>
    <item name="android:windowEnterTransition">@android:transition/slide_right</item>
    <item name="android:windowExitTransition">@android:transition/slide_left</item>
</style>

, и это прекрасно работает.

, но без установки границ вручную, просто не будет отображаться рисование ...

Почему рисование не отображается, если я не устанавливаю границы?И есть ли способ сделать это без ручной установки размера?

...