簡體   English   中英

如何刪除動作欄圖標的空間?

[英]How do I remove the space of the actionbar icon?

我使用getActionBar()。setDisplayShowHomeEnabled(false);刪除了該圖標。

我正在使用imageview應該填充整個動作欄。 我想這樣做,因為我希望圖像作為標題欄包括徽標和textview。 但是仍然希望能夠使用動作欄功能。 因此,發生的事情是它與圖標以前的位置存在一個起點差距。 使用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

這就是我要作為動作欄

這解決了我的問題:

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>

ImageView刪除android:layout_marginStart = "20dp"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM