Страница 1 из 1

Material toolbar

Добавлено: 21 июл 2015, 15:24
ANdriy123456
Как удалить material menu (burger-arrow) в toolbar?

Код: Выделить всё

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/top_green">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/ab_menu"
        android:padding="10dp"
        android:src="@mipmap/menu_icon" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/app_name"
        android:id="@+id/textView"
        android:textColor="@color/white"
        android:layout_weight="1"
        android:gravity="center"
        android:singleLine="true"
        android:layout_marginRight="10dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/custom_search"
        android:src="@mipmap/search_icon"
        android:padding="10dp" />

    </LinearLayout>
</LinearLayout>

Код: Выделить всё

mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(false);
mToolbar.setCollapsible(false);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View custom = (View) inflater.inflate(R.layout.custom_ab, null);
Toolbar.LayoutParams params = new Toolbar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mToolbar.addView(custom, params);

Re: Material toolbar

Добавлено: 21 июл 2015, 15:41
klblk
Собственно зачем тут вообще кастомное View?
1) Иконка слева вроде бы задается методом toolbar.setNavigationIcon();
2) Иконка справа делается с помощью меню;
3) Текст по центру.... ну ту вероятно придется костомное View использовать (но тут будет всего лишь один TextView), хотя может есть более элегантное решение.

Re: Material toolbar

Добавлено: 21 июл 2015, 15:46
ANdriy123456
toolbar.setNavigationIcon(); не работает (ни перед mToolbar.addView(custom, params) ни после него). в кастомном xml есть и другие елементы.

Re: Material toolbar

Добавлено: 21 июл 2015, 18:15
Mikhail_dev
klblk писал(а):Собственно зачем тут вообще кастомное View?
1) Иконка слева вроде бы задается методом toolbar.setNavigationIcon();
2) Иконка справа делается с помощью меню;
3) Текст по центру.... ну ту вероятно придется костомное View использовать (но тут будет всего лишь один TextView), хотя может есть более элегантное решение.
И это элегантное решение - ToolBar

Попробуйте оба флага эти
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(false);