I want to place buttons in a tab layout and use these buttons to call different fragments in a tab layout. Moreover I want to place some image in each button .Can anyone please help ??
Asked
Active
Viewed 1,698 times
1 Answers
0
You can use ImageButton in your xml file and align it to the bottom of the page and set the text and back image of the ImageButton from code section. somthing like this:
the_xmlLayout:
<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">
<ImageButton
android:id="@+id/theImageButton"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
And somthing like this in your java code:
View v = (View) getActivity().getLayoutInflater().inflate(R.layout., null);
ImageButton ib = (ImageButton) v.findViewById(R.id.theImageButton);
ib.setBackgroundResource(R.drawable.X);
You cand define a method to change the background randomly with setBackgroundResource method.

Babak-Na
- 104
- 1
- 1
- 8