Android How To Add Tooltip Message Near To A View

June 05, 2018 , 0 Comments

Tooltip is a simple popup message tip shown near to a view. It is similar to its web version that shown when you mouse over it. It is helpful for giving special or extra information about a UI element in the page. From API Level 26 Android introduces new property called android:tooltipText through this we achieve Tooltip funtionality.


Prerequisites


API Level : 26 (Android 8.0) and higher


Implementation


Let’s see how to set the Tooltip for a view in the layout.


Method 1: Define It In Layout


android:layout_width="match_parent"
android:layout_height="match_parent">

android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="Hello Devdeeds.com"
android:textColor="#000"
android:textSize="18sp" />

android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:text="Next"
android:textAllCaps="false"
android:textSize="16sp"
android:tooltipText="This will take you to next page" />



Method 1: Set It Programmatically

Let’s see how to set the Tooltip in the Activity Class.



import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatButton;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

AppCompatButton btnNext = (AppCompatButton) findViewById(R.id.next_button);
btnNext.setTooltipText("This will take you to next page");
}
}

How To Get The Tooltip Property Value


The API has getTooltipText() method by which you can get the value of the tooltipText property.


The post Android How To Add Tooltip Message Near To A View appeared first on DevDeeds.

Unknown

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Hot-product

Best Watch Store

Popular Posts

Contact Form

Name

Email *

Message *