I am trying to get an ImageSlider activity using PageAdapter with following features:-
- Translucent Background.
- Translucent Custom Action Bar, with TextView and ImageButtons.
Problems I am facing:-
- To make the activity translucent, I added
android:theme="@android:style/Theme.Translucent
to the<activity>
of Manifest andandroid:background="#20000000"
in XML layout file. But after doing thisgetActionBar()
in myonCreate()
method is returning null. If I removeandroid:theme="@android:style/Theme.Translucent
then the activity is no longer translucent butgetActionBar()
is now working.
I am using getActionBar()
to inflate a custom translucent Action bar, so as of now either I can get translucent activity or a custom action bar, not both of them at once.
- TextView in my Custom Action Bar is for showing the current image no out of total no of images, like 1 out of 5 and slide to right to get 2 out of 5, and so on.
But sometimes it shows correctly, sometimes just random numbers.
My code:-
TextView header;
int count=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Getting Action Bar
ActionBar mActionBar= getActionBar();
LayoutInflater minflate =(LayoutInflater) mActionBar.getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
mview = minflate.inflate(R.layout.albumactionbar,null);
mActionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,ActionBar.DISPLAY_SHOW_CUSTOM|ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_TITLE);
mActionBar.setCustomView(mview, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT));
header =(TextView)mview.findViewById(R.id.action_text);
setContentView(R.layout.albummainview);
}
albumactionbar.xml:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/custom_ab"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/album_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_back"
android:layout_alignParentLeft="true"
android:background="@color/Translucent"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/action_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_gravity="center"
android:text="Gallery Count"
android:textSize="18sp"
android:layout_centerInParent="true"/>
<ImageButton
android:id="@+id/album_after"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_after"
android:layout_alignParentRight="true"
android:background="@color/Translucent"
android:layout_gravity="center"
/>
</RelativeLayout>
custom_ab.xml:-
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="#FF000000"
android:endColor="#00000000"
android:angle="270"
/>
</shape>
Now inside MyAdpater, I am changing the header
TextView value of the custom Action bar:-
public class AlbumAdapter extends PagerAdapter
{
Context context;
public AlbumAdapter(Context context){
this.context = context;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
View viewItem = inflater.inflate(R.layout.albumitemview, container, false);
//header is the custom action bar's text view.
header.setText((position+1)+" out of "+count);
.....
}
}
So please guide me in solving both the problems, and regarding problem 2, is it the right place to change the textView's value?