简体   繁体   English

我可以在 android 工作室中将工具栏图标浮动到左上方吗?

[英]Can i float to top left an a toolbar icon in android studio?

I have this:我有这个:

在此处输入图像描述

But i want to float home icon to top left like:但我想将主页图标浮动到左上角,例如:

在此处输入图像描述

I have this into my menu_main.xml file我在menu_main.xml文件中有这个

<?xml version="1.0" encoding="utf-8"?>
<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/action_notificaciones"
        android:orderInCategory="300"
        android:title="User"
        android:icon="@drawable/ic_notificaciones"
        app:showAsAction="ifRoom"></item>

    <item
        android:id="@+id/action_home"
        android:orderInCategory="300"
        android:title="User"
        android:icon="@drawable/ic_go_home"
        app:showAsAction="ifRoom"></item>


</menu>

How could i do this?我怎么能这样做? Any help?有什么帮助吗?

u can use toolbar and set imageview for the icon and textview for tittle,,this a example您可以使用工具栏并设置 imageview 为图标和 textview 为标题,这是一个例子

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbarTransaction"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageView
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="50dp"
                android:src="@drawable/img_vireopos_icon"/>\

            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:textSize="10pt"
                android:text="testing"/>

            <ImageView
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="50dp"
                android:src="@drawable/img_vireopos_icon"/>\


        </LinearLayout>

    </androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM