Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Button Tooltip

Tags:

android

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" />
like image 991
c12 Avatar asked Mar 15 '26 05:03

c12


1 Answers

(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>
like image 98
Sam Avatar answered Mar 16 '26 20:03

Sam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!