2

Решил попробовать использовать Toolbar в приложении, вот такого вида он у меня сейчасвид
Не получается добавить отступ между иконками и текстом. Подскажите как мне его добавить? Свойства margin и padding не работают. Вот мой код:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/action_bar_height"
    android:background="@color/action_bar_background"
    app:contentInsetStart="@dimen/content_insert"
    app:contentInsetEnd="@dimen/content_insert">

    <ImageButton
        android:id="@+id/image_button_previous"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/arrow_left"
        android:contentDescription="@string/action_previous_activity"
        android:onClick="onClick"/>

    <TextView
        android:id="@+id/text_view_previous"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/action_previous_activity"
        android:textSize="@dimen/action_bar_text_size"
        android:textColor="@color/action_bar_text"
        android:onClick="onClick"/>

    <ImageButton
        android:id="@+id/image_button_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/arrow_right"
        android:contentDescription="@string/action_next_activity"
        android:layout_gravity="end"
        android:onClick="onClick"/>

    <TextView
        android:id="@+id/text_view_previous_next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/action_next_activity"
        android:textSize="@dimen/action_bar_text_size"
        android:textColor="@color/action_bar_text"
        android:layout_gravity="end"
        android:onClick="onClick"/>

</android.support.v7.widget.Toolbar>

7
  • Нарисовать картинку с отступом?
    – cpp_user
    7 июл 2015 в 18:32
  • 1
    вариант, но хотелось бы по правильному) 7 июл 2015 в 19:43
  • Оберни все в контейнер, например, LinearLayout. Там можешь задать отступы и все, что надо. Этот контейнер помести в Toolbar.
    – pavlofff
    7 июл 2015 в 19:53
  • пробовал, также отступы не работают 7 июл 2015 в 20:14
  • А использовать android:drawableLeft и android:drawableRight для TextView не пробовал? Им можно задать drawablePadding
    – Mikhail
    7 июл 2015 в 22:28

2 ответа 2

2

Вариант ужасный, но рабочий.

View v = findViewById(android.R.id.home);
if (null != v) {
    ((View) v.getParent().getParent()).setPadding(32, 0, 0, 0);
}
1

Вопрос решен, неправильно указал в разметке отступы.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.