Toolbar with four icons how can set like this image?

后端 未结 2 1195
无人共我
无人共我 2021-01-26 09:42

Toolbar with four icons how can set like this image ?

I want to set four icons like image in toolbar.

i have make toolbar . & setting icons in menu_main.xml

相关标签:
2条回答
  • 2021-01-26 10:25

    Use customize view for toolbar

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        LayoutInflater inflater = (LayoutInflater) getSupportActionBar().getThemedContext()
                .getSystemService(LAYOUT_INFLATER_SERVICE);
    
        final View customActionBarView = inflater.inflate(
                R.layout.actionbar_customview, null);
    
        final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
        //actionBar.setIcon(R.drawable.action_appicon);
        actionBar.setCustomView(customActionBarView);
        actionBar.setDisplayShowCustomEnabled(true);
    

    actionbar_customview.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="left">
    
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/upgrade"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:paddingRight="7dp"
        android:paddingLeft="5dp"
        android:textSize="11dp"
        android:textColor="#c23c3c"
        android:textAllCaps="false"
        android:drawableLeft="@drawable/upgrade"
        android:drawablePadding="5dp"
        android:background="@drawable/upgrade_button_round"
        android:id="@+id/button" />
    
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
       <ImageView
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/noticication_icn"
            android:layout_alignParentRight="true"
            android:id="@+id/notificationID"/>
    
        <TextView
            android:id="@+id/notificationsCount"
            android:layout_marginTop="5dp"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_alignParentRight="true"
            android:textSize="10sp"
            android:textAlignment="center"
            android:background="@drawable/textviewcircle"
            android:textColor="@color/white"
            />
    
    </RelativeLayout>
    
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp">
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ppp_icn" />
    </RelativeLayout>
    

    MainActivity.xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 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"
    android:id="@+id/projectCoordinate"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    
    </android.support.design.widget.AppBarLayout>
    
    <include layout="@layout/content_main" />
    
    
    </android.support.design.widget.CoordinatorLayout>
    
    0 讨论(0)
  • 2021-01-26 10:43
    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);
    }
    
    0 讨论(0)
提交回复
热议问题