0
我試圖自定義ActionBar以顯示徽標。我第一次嘗試做這樣用自定義佈局覆蓋ActionBar
actionBar.setIcon(R.drawable.logo);
但我需要這是一個大一點,所以我試圖創建一個自定義佈局和膨脹它在默認的動作條。
我收穫了幾個教程,幾乎所有匹配在相同的過程。所以,我去與它:
custom_actionbar.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/ablogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="@drawable/logo" />
</RelativeLayout>
MainActivity.java - > onCreate()方法
actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
/*Inflate your custom actionBar layout*/
View customActionBar = getLayoutInflater().inflate(R.layout.custom_actionbar, null);
actionBar.setCustomView(customActionBar);
但我意識到,自定義動作條佈局沒有填充整個操作欄。應該在左側的徽標圖像位於操作欄的中間,即使默認圖標和標題未顯示,操作欄也不會觸及它們的空間。
那麼,應該如何正確的方式來覆蓋操作欄,並能夠在左側設置我的標誌圖像?
既不是這樣,我得到它 – masmic 2014-09-24 13:23:37
自定義操作欄不顯示上面的代碼。 – 2014-09-24 13:34:20