Shishi
Shishi

Reputation: 611

How do I remove the space of the actionbar icon?

I removed the icon using getActionBar().setDisplayShowHomeEnabled(false);

I'm using a imageview with should fill the whole actionbar. I want to do it this way because I want the image as titlebar including the logo and a textview. But still want to be able to use actionbar functions. So what happened is that it has a start gap where the icon used to be. Using match_parent or fill_parent.

titlebar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="horizontal"
       android:layout_width="fill_parent"
       android:layout_height="match_parent"  
       android:gravity="center_vertical"     
       android:background="@android:color/white">

       <ImageView
              android:id="@+id/header"
              android:contentDescription="@string/app_name"
              android:background="@drawable/ic_launcher"
              android:layout_width="150dp"
              android:layout_height="150dp"
              android:layout_marginStart = "20dp"/>

       <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginStart="40dp"
              android:layout_marginTop = "5dp"
              android:text="@string/titlebarText"
              android:gravity ="right"
              android:textColor="@android:color/black"
              android:textStyle="bold"
              />             
</LinearLayout>

https://i.sstatic.net/Tflyq.png

That is what I want to make as actionbar

Upvotes: 0

Views: 1985

Answers (2)

Shishi
Shishi

Reputation: 611

This fixed my problem :

MainActivity.java

// Set up the action bar.
final ActionBar actionBar = getActionBar();
//set custom actionbar
actionBar.setCustomView(R.layout.titlebar);
//Displays the custom design in the actionbar
actionBar.setDisplayShowCustomEnabled(true);
//Turns the homeIcon a View     
View homeIcon = findViewById(android.R.id.home);
//Hides the View (and so the icon)
((View)homeIcon.getParent()).setVisibility(View.GONE);

titlebar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="horizontal"
       android:layout_width="fill_parent"
       android:layout_height="match_parent"
       android:gravity="center_vertical"
       android:background="@android:color/white">

       <ImageView
              android:id="@+id/header"
              android:contentDescription="@string/app_name"
              android:background="@drawable/ic_launcher"
              android:layout_width="150dp"
              android:layout_height="150dp"/>

       <TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/titlebarText"
              android:gravity ="right"
              android:textColor="@android:color/black"
              android:textStyle="bold"
              />             
</LinearLayout>

Upvotes: 2

user543
user543

Reputation: 3633

remove android:layout_marginStart = "20dp" in ImageView

Upvotes: 1

Related Questions