如何更改工具栏名称并在工具栏上放置图标

All*_*lil 5 android android-studio android-toolbar

我刚刚使用导航视图的 android studio 模板制作了该应用程序。一切正常,但我有以下两个要求

  1. 我想将工具栏标题居中。
  2. 我想把图片放在标题旁边。

这是我的 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.abdulsalam.lahoreqalander.MainActivity">

<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.FloatingActionButton-->
    <!--android:id="@+id/fab"-->
    <!--android:layout_width="wrap_content"-->
    <!--android:layout_height="wrap_content"-->
    <!--android:layout_gravity="bottom|end"-->
    <!--android:layout_margin="@dimen/fab_margin"-->
    <!--android:src="@android:drawable/ic_dialog_email" />-->
Run Code Online (Sandbox Code Playgroud)

问题 :

我不知道标题字符串保存在哪里,我检查了 string.xml 并且有应用程序名称,并且它准确地显示在工具栏标题上。

所以任何建议我可以在哪里更改标题字符串而不更改应用程序名称,事实上我想更改它自定义以及如何将图像放在它旁边。

注意我使用的是Android studio制作的模板

Vip*_*sri 4

您可以在 XML 中像这样实现。

<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">

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

          <ImageView
            android:src="@mipmap/ic_launcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

          <TextView
            style="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
            android:text="@string/app_name"
            android:background="?attr/selectableItemBackground"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)