2013-07-25 57 views
1

下面是我當前設置的屏幕截圖。Android自定義操作欄刪除圖標

enter image description here

我創建了一個自定義操作欄視圖,我在下面的代碼設置,並且我想是兩個圖像,一個在左邊的標題欄排列,其他的右對齊。

問題是,當我隱藏應用程序圖標時,它只會隱藏它,不會刪除它,因此左邊的空白。我發現了一些其他的SO問題,展示瞭如何刪除圖標,但這也刪除了我想保留的選項卡。

任何人都可以爲我提供解決方案嗎?

從我的onCreate()函數:

final ActionBar actionBar = getActionBar(); 
     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);  

     LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View v = inflater.inflate(R.layout.action_bar_title, null); 

     View homeIcon = findViewById(android.R.id.home); 
     ((View) homeIcon.getParent()).setVisibility(View.GONE); 
     ((View) homeIcon).setVisibility(View.GONE);   

     actionBar.setDisplayShowCustomEnabled(true); 
     actionBar.setDisplayShowTitleEnabled(false); 
     actionBar.setDisplayShowHomeEnabled(true); 
     actionBar.setCustomView(v); 

我的XML定製佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" 
    android:gravity="fill_horizontal" 
    android:layout_marginLeft="0dp" 
    android:orientation="horizontal" 
    >  

    <ImageView android:id="@+id/title_img_left" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true" 
        android:layout_alignParentTop="true"      
        android:src="@drawable/test" /> 
    <ImageView android:id="@+id/title_img_right" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_alignParentRight="true" 
        android:layout_alignParentTop="true" 
        android:src="@drawable/test" /> 


</RelativeLayout> 

我使用Holo.Light.DarkActionBar主題,我相信。

+0

這沒有iPhone。操作欄中的按鈕應該位於右側。 – bofredo

+0

所以,試試用你自己的風格繼承sherlock widget吧 – deadfish

+0

@bofredo我不明白iPhone與任何東西有什麼關係。他們不是按鈕,他們是圖像,這就是我希望他們在Android的設計 – TomP89

回答

0

因此,如果我理解你正在努力實現的目標,爲什麼不在你的左側添加一個MenuItem的自定義圖像,併爲你設置actionBarLogo的圖像,你想在右側。之後,只是重寫主頁按鈕單擊,我想你會實現相同的東西,你可以用自定義視圖創建,沒有ActionBar左側的填充。

附:如果我理解你錯了,請提供一些關於它應該如何的信息。

0

該代碼正在工作!

ActionBar actionBar = getSherlockActivity().getSupportActionBar(); 

     View customNav = LayoutInflater.from(getActivity()).inflate(R.layout.custom_action_bar_view, null); 
     ImageButton imageButton = (ImageButton) customNav.findViewById(R.id.imageButton); 

     ActionBar.LayoutParams lp = new ActionBar 
      .LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 
     actionBar.setCustomView(customNav, lp); 
     actionBar.setDisplayShowCustomEnabled(true); 
     actionBar.setDisplayShowTitleEnabled(false); 
     actionBar.setDisplayShowHomeEnabled(false);