2014-01-23 9 views
0

Я удалил значок, используя getActionBar(). SetDisplayShowHomeEnabled (false);Как удалить пробел значка панели действий?

Я использую изображение, чтобы заполнить всю панель действий. Я хочу сделать это так, потому что я хочу, чтобы изображение как заголовок включало логотип и текстовое изображение. Но все же хотите иметь возможность использовать функции панели действий. Так что произошло, так это то, что у него есть начальный пробел, где раньше была икона. Использование match_parent или 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> 

http://i.imgur.com/3eTldKh.png

Это то, что я хочу сделать как ActionBar

ответ

2

Это фиксированная моя проблема:

MainAct ivity.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> 
1

удалить android:layout_marginStart = "20dp" в ImageView

+0

сначала смотрел, как она работает, но когда я повернул мой экран проблема возвращается с еще более широким пространством. Когда я использую fill_parent на моем ImageView, половина экрана пуста, удерживая устройство вертикально и около 3/4 пустым, удерживая горизонтально – Shishi

+0

r u имеет проблему с правой правой частью текстового поля при изменении ориентации? – user543

+0

Пространство находится в левой части изображения. Я пытаюсь сделать более толстую панель действий с большим логотипом и некоторым текстом. – Shishi

Смежные вопросы