Android Button Tooltip

2020-03-26 06:21发布

iOS implemenatation

I'm new to Android and I was wondering if is possible to have an Android button element that has an embedded tooltip? I would like to have an image on the button, that when pressed opens up a dialog/tootip overlay of some sort. So not a hover tooltip, but a clickable element that goes somewhere other than where the button click goes. If someone could guide me as to the best practice for this that would be great!

<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:paddingLeft="5dip" 
    android:paddingRight="5dip">

    <Button android:id="@+id/settings_predefined_message_btn"
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"
        android:text="@string/settings_predefined_messages"
        android:background="@drawable/selector_longbutton_witharrow" 
        style="@style/ButtonTextStyle"
        android:layout_marginTop="10dip" 
        android:gravity="center" />

标签: android
1条回答
做自己的国王
2楼-- · 2020-03-26 06:52

(In response to your last comment about setting on view on top of another.)

Simple, you could use multiple LinearLayouts like this:

<LinearLayout
    android:id="@+id/tab1"
    ... />

    <TextView
        android:text="Predefined Message"
        ... />

    <ImageButton
        ... />

</LinearLayout>

Your LinearLayout (and maybe the TextView) should have one OnClickListener to do the main feature, the ImageButton will have a second OnClickListener for the tooltip.

Or you could use a RelativeLayout to position the tooltip ImageButton with an OnClickListener on top of the TextView with its own OnClickListener.

You can pass either of these custom view to an ActionBar to build the tabs for you, if you like. Hope that helps.

Addition

An (ugly!) RelativeLayout example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="A long text sample"
        />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button1"
        android:layout_marginRight="10dp"
        android:text="i"
        />

</RelativeLayout>
查看更多
登录 后发表回答