工具栏上有四个图标如何设置像这样的图像? [英] Toolbar with four icons how can set like this image?

查看:66
本文介绍了工具栏上有四个图标如何设置像这样的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带有四个图标的工具栏如何设置像此图像?

Toolbar with four icons how can set like this image ?

我想在工具栏中设置四个图标,例如图像.

I want to set four icons like image in toolbar.

我有make工具栏. &在menu_main.xml中设置图标.但是我没有得到.为什么有人能帮助我为什么它不出现?

i have make toolbar . & setting icons in menu_main.xml .But i am not getting .Why could any one help me why it is not coming ?

styles.xml

styles.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
</resources>

toolbar.xml

toolbar.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:minHeight="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:titleTextColor="@android:color/white"
        android:background="#f26925"

       >
    </android.support.v7.widget.Toolbar>
    <!--<TextView
        android:id="@+id/toolbar_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Mumbai"
        android:textColor="@android:color/white"
        style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
        android:layout_gravity="left"
        />-->
    <!-- Layout for content is here. This can be a RelativeLayout  -->

</LinearLayout>

menu_main.xml

menu_main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity">
    <item
        android:id="@+id/bookmark"
        android:icon="@drawable/bookmark"
        app:showAsAction="ifRoom"
        android:title="Compose">
    </item>
    <item
        android:id="@+id/search"
        android:icon="@drawable/search"
        app:showAsAction="ifRoom|withText"
        android:title="Profile">
    </item>
    <item
        android:id="@+id/loc"
        android:icon="@drawable/loc"
        app:showAsAction="ifRoom|withText"
        android:title="Profile">
    </item>
    <item
        android:id="@+id/menu"
        android:icon="@drawable/menu"
        app:showAsAction="ifRoom|withText"
        android:title="Profile">
    </item>
</menu>

使用此工具后,我在工具栏中没有显示图标.没有出现图标,为什么?

After using this i am not getting icons in toolbar. no icon is appearing why ?

推荐答案

Please add menu inflating code inside your Activity
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    return super.onCreateOptionsMenu(menu);
}

这篇关于工具栏上有四个图标如何设置像这样的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆