Reputation: 141
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
Upvotes: 1
Views: 2949
Reputation: 61
At styles.xml first make a style for action bar with no title and with the logo like that
<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
android:theme="@style/AppTheme.Main"
I wish that help everyone
Upvotes: 0
Reputation: 69671
Try this you can use custom toolbar for that purpose in your 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:
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 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
Upvotes: 2
Reputation: 89
If you are using Actionbar then just do as following if you want to do it with java code:
getSupportActionBar().setTitle("");
getSupportActionBar().setIcon(R.drawable.your_icon);
Or on the Manifest 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);
Upvotes: 0