如何在Android Studio中将应用标题更改为徽标

问题描述:

如何将应用标题更改为徽标?似乎这个代码不工作,当我建立应用程序时,仍然在那里删除应用程序标题。如何在Android Studio中将应用标题更改为徽标

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

enter image description here

谢谢

试试这个,你可以使用自定义工具栏,为此目的在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> 

现在设置工具栏的标题和标志像这样在onCreate()方法的activity.java文件中:

​​

不要忘了在style.xml添加此主题的活动:

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

或者你可以试试这个,如果你不希望使用自定义工具栏:

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 
+0

你好感谢你的答案,但我应该在哪里放呢?似乎有很多错误,当我把放在AndroidManefest.xml上,所以对不起im新的android im仍然在学习 – GravityCode

+0

也工具栏工具栏顶部......代码时我把代码的ImageView变成红色,当我把导入android.widget.ImageView;没有事情发生。 – GravityCode

+0

@GravityCode它在我的设备上工作正常 –

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

或者在清单XML:如果你想使用Java代码来做到这一点。如果你使用的是动作条则只是做如下

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

对您的活动。

,如果要启用重新点击您的标志,然后使用:

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