How to make button that shows a list of options on long click, like on the Soft Keyboard
I want to use/create a b开发者_StackOverflowutton that works like the one on the (HTC Desire) Soft Keyboard. So that when you make a long click, it will show a list of options, and by sliding your finger to the left or right, you select which option you want to choose.
Example: When I hold down the "12#" button on the keyboard, it presents the list: [: / @ _ - ! ? '], and by sliding left or right it highlights one of these characters and chooses the selected one when I release my finger. If I just click normally, it selects the default character.
Is there such a widget in the Android SDK, or can anyone give a hint on how to implement such a component.
See screenshot: Entering text, and just long pressed the "12#" button. "!" is currently selected.
- Create a custom Activity with
android:theme="@android:style/Theme.Dialog"
(this will give it a transparent, floating dialog look). - Add to it a
LinearLayout
withandroid:orientation="horizontal"
Add some button with icons to
LinearLayout
. This creates a transparent Button with an Icon and some text beneath it:<Button android:id="@+id/optionsButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dip" android:text="@string/button_options_text" android:textColor="@color/button_text_grey" android:drawableTop="@drawable/button_options" android:drawablePadding="-5dip" android:background="@null"
Use Button.onKeyLongPress(..) to show this Activity.
精彩评论