如何在操作栏中添加textview而不是带有图像的应用程序名称

时间:2017-02-06 13:10:01

标签: android android-layout android-actionbar android-actionbar-compat

我想添加带有图像的Textview,而不是应用程序名称:

enter image description here

我不想删除菜单图片。我只是想从操作栏中删除应用名称,并将这种文本视图放在该点击上,我想要显示吐司。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

  

您可以制作自己的应用栏xml。使用include标记包含要显示的应用栏。别忘了在样式中将主题定义为NoActionBar。

    <include
        layout="@layout/tool_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

这里是工具栏xml

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v7.widget.Toolbar  xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/header_color"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">


<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:paddingTop="5dp">
    <LinearLayout

        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="0.2"
        android:orientation="horizontal"
        android:gravity="center">



    </LinearLayout>

    <LinearLayout

        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3.5"
        android:orientation="horizontal"
        android:gravity="center_vertical">
        <TextView
            android:id="@+id/txtTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            />



    </LinearLayout>
    <LinearLayout

        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:gravity="center">
        <ImageView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageViewNotification" />


    </LinearLayout>
    <LinearLayout

        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:gravity="center">


        <ImageView
            android:src="@drawable/tab_bar_profile"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageViewlogin" />
    </LinearLayout>
</LinearLayout>

答案 1 :(得分:0)

 ActionBar action = getSupportActionBar(); //get the actionbar

action.setCustomView(R.layout.your_bar);//add the custom view
action.setDisplayShowTitleEnabled(false); //hide the title

之后,使用textView,imageVie等进行布局。 希望帮助你:D