I using Action Bar.In which using an spinner I want it's title should be image/icon and select-able item should be text and after clicking on icon it will display subtitles .I want to have only the icon in the ActionBar and the drop-down-list/spinner to appear when tapped on the icon.There Is an example Spinner in action bar with only icon but not the selected option but does not solve my problem.I want to have only the icon in the ActionBar and the drop-down-list/spinner to appear when tapped on the icon.New In Android.Help Me.
Asked
Active
Viewed 843 times
2 Answers
0
You need to take one button and set any image as its background.Then on click of the button call Spinner.performClick() to open the spinner.
Below is code to implement the same thing. In xml file:
<Button
android:id="@+id/font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="50dp"
android:layout_weight="0.5"
android:background="@drawable/textsel" />
<Spinner
android:id="@+id/spin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_weight="0.5"
android:dropDownHorizontalOffset="0dp"
android:dropDownVerticalOffset="20dp"
android:dropDownWidth="500dp"
android:paddingTop="2sp"
android:spinnerMode="dropdown" >
</Spinner>
In Java class:
Spinner spin = (Spinner) findViewById(R.id.spin);
Button typetext = (Button) findViewById(R.id.font);
typetext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
spin.performClick();
}
});

Jigar Pandya
- 2,129
- 2
- 17
- 27
0
On the setOnItemSelected Listener,
you could write
if (((TextView) view) != null) {
((TextView) view).setText(null);
}
That way you will only have the icon displayed and not the text. And set the background to the icon drawable u want.
Hope that helps.

Rat-a-tat-a-tat Ratatouille
- 7,109
- 5
- 31
- 41