I wanted to create a drop down menu on clicking an image button.Do i need to create a spinner for this?Could you please tell me how to create a drop down menu using spinner?
Asked
Active
Viewed 4,802 times
4 Answers
2
Add this attribute in the button in the xml file
android:background="@android:drawable/btn_dropdown"
and you get a drop down image in the button and in the click of the button you can perform your operation

jyomin
- 1,957
- 2
- 11
- 27
1
USE BELOW GIVEN CODE IN YOUR PROJECT :
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();
}
});
You can ask if you have any further queries!

Jigar Pandya
- 2,129
- 2
- 17
- 27
0
-
How to design an image button in such a way that when i click the image button it as to list some info? – Dharni Nov 05 '13 at 07:00