0

我在我的項目中使用了actionbarshearlock庫。 我想要操作欄是透明的。 如何做到這一點? 在此先感謝。actionbarshearlock活動中的透明操作欄

+0

@Imram汗:檢查我的編輯答案:http://stackoverflow.com/a/15873047/1168654 – 2013-04-08 10:14:43

回答

4

enter image description here


不使用actionbarshearlock:


剛添加此行:requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

onCreate

setContentView(R.Layout.Test)這行之前給你TRANSPARENT ActionBar

getActionBar().setBackgroundDrawable(
        getResources().getDrawable(R.drawable.ab_bg_black)); 

,如:

@Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 
     setContentView(R.layout.activity_main); 

     getActionBar().setBackgroundDrawable(
       getResources().getDrawable(R.drawable.ab_bg_black)); 
} 

爲R.drawable.ab_bg_black只是像string.xml添加繪製顏色:

<drawable name="ab_bg_black">#80000000</drawable> 

同樣的方式使用actionbarshearlock:


@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     setTheme(SampleList.THEME); //Used for theme switching in samples 
     requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.overlay); 

     //Load partially transparent black background 
     getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black)); 

} 

編輯:Start listview After Actionbar.

enter image description here

如果您使用actionbarshearlock然後就去做象下面這樣:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     android:paddingTop="?actionBarSize" > 
    </ListView> 

</LinearLayout> 
+0

Dhaval Sodha帕爾馬非常感謝你保存我的日子 一個問題更多我有一個清單,我的清單應該在操作欄下面 – 2013-04-08 07:23:22

+0

@ImranKhan:我的榮幸.... – 2013-04-08 07:34:55

+0

有一個問題更多我有一個清單,我的清單應該在操作欄下方如何操作 – 2013-04-08 08:34:41

2

試試這個代碼,但我不知道這正是你所需要的:

bar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));