Reputation: 158
i am using actionbarshearlock library in my project. I want the action bar to be transparent. How to do it? thanks in advance.
Upvotes: 0
Views: 1886
Reputation: 18978
without use actionbarshearlock:
just add this line: requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
before setContentView(R.Layout.Test)
in onCreate
and this line give you TRANSPARENT ActionBar
getActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.ab_bg_black));
like:
@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));
}
for R.drawable.ab_bg_black just add drawable colour in string.xml like:
<drawable name="ab_bg_black">#80000000</drawable>
same way using 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));
}
Edited: Start listview After Actionbar.
if you are using actionbarshearlock then just do like below:
<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>
Upvotes: 4
Reputation: 3211
try this code, but I'm not sure that is exactly what you need:
bar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Upvotes: 2