简体   繁体   English

Android Studio中如何将App title改为Logo

[英]How to Change App title to Logo in Android Studio

How to change the App Title to a Logo?如何将应用标题更改为徽标? seems this code is not working to Remove the App Title still in there when i build the app.当我构建应用程序时,此代码似乎无法删除仍然存在的应用程序标题。

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

在此处输入图像描述

Thank you谢谢

Try this you can use custom toolbar for that purpose in your layout.xml: 尝试此操作,您可以在layout.xml中为此目的使用定制工具栏:

    <android.support.v7.widget.Toolbar
     android:id="@+id/toolbar_top"
     android:layout_height="wrap_content"
     android:layout_width="match_parent"
     android:minHeight="?attr/actionBarSize"
     app:layout_collapseMode="parallax"
     app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >


      <Imageview
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@mipmap/ic_launcher"
        android:id="@+id/toolbar_title" />


</android.support.v7.widget.Toolbar>

Now set the title and logo of your toolbar like this in your activity.java file in onCreate() method: 现在,在onCreate()方法中的activity.java文件中设置工具栏的标题和徽标,如下所示:

Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
Imageview mTitle = (Imageview) toolbarTop.findViewById(R.id.toolbar_title);
imageView.setBackgroundResource(R.drawable.logo);

Don't forget to add this theme in style.xml to your activity: 不要忘记在style.xml中将此主题添加到您的活动中:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

Or you can try this if you don't want to use custom toolbar: 或者,如果您不想使用自定义工具栏,也可以尝试以下方法:

 ActionBar actionBar = getSupportActionBar()
actionBar.setIcon(R.mipmap.ic_launcher_round);  // showing the icon to your action bar 
actionBar.setTitle("");//set title to your action bar

If you are using Actionbar then just do as following if you want to do it with java code: 如果您使用的是Actionbar,则要使用Java代码执行以下操作:

getSupportActionBar().setTitle("");
getSupportActionBar().setIcon(R.drawable.your_icon);

Or on the Manifest xml : 或在清单xml上:

<activity android:name=".YourActivity" 
   android:icon="@drawable/your_icon" 
   android:label="" />

on your activity. 关于你的活动。

and if you want to enable back on clicking your logo then use: 如果您想启用重新单击徽标的功能,请使用:

getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);

At styles.xml first make a style for action bar with no title and with the logo like that在 styles.xml 首先为没有标题和标志的操作栏制作一个样式

<style name="ActionBar.NoTitle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <item name="displayOptions">useLogo|showHome</item>
        <item name="logo">@drawable/ic_logo</item>
    </style>

Then create custome theme for your activity with new actionbar style然后使用新的操作栏样式为您的活动创建自定义主题

<!-- Create a style for MainActivity called AppTheme.Main that uses our custom ActionBar style -->

<style name="AppTheme.Main" parent="@style/AppTheme">
    <item name="actionBarStyle">@style/ActionBar.NoTitle</item>
</style>

Then go to manifest file under the specified activity set theme to AppTheme.Main然后go到指定activity下的manifest文件设置主题为AppTheme.Main

android:theme="@style/AppTheme.Main"

I wish that help everyone希望对大家有所帮助

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

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