public class

TooltipCompat

extends java.lang.Object

 java.lang.Object

↳androidx.appcompat.widget.TooltipCompat

Gradle dependencies

compile group: 'androidx.appcompat', name: 'appcompat', version: '1.6.0-alpha04'

  • groupId: androidx.appcompat
  • artifactId: appcompat
  • version: 1.6.0-alpha04

Artifact androidx.appcompat:appcompat:1.6.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.appcompat:appcompat com.android.support:appcompat-v7

Androidx class mapping:

androidx.appcompat.widget.TooltipCompat android.support.v7.widget.TooltipCompat

Overview

Helper class used to emulate the behavior of View prior to API level 26.

Summary

Methods
public static voidsetTooltipText(View view, java.lang.CharSequence tooltipText)

Sets the tooltip text for the view.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static void setTooltipText(View view, java.lang.CharSequence tooltipText)

Sets the tooltip text for the view.

On API 26 and later, this method calls through to View.

Prior to API 26, this method sets or clears (when tooltipText is null) the view's OnLongClickListener and OnHoverListener. A tooltip-like sub-panel will be created on long-click or mouse hover.

Parameters:

view: the view on which to set the tooltip text
tooltipText: the tooltip text

Source

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.appcompat.widget;

import android.os.Build;
import android.view.View;

import androidx.annotation.DoNotInline;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

/**
 * Helper class used to emulate the behavior of {@link View#setTooltipText(CharSequence)} prior
 * to API level 26.
 *
 */
public class TooltipCompat  {
    /**
     * Sets the tooltip text for the view.
     * <p>
     * On API 26 and later, this method calls through to {@link View#setTooltipText(CharSequence)}.
     * <p>
     * Prior to API 26, this method sets or clears (when tooltipText is {@code null}) the view's
     * {@code OnLongClickListener} and {@code OnHoverListener}. A tooltip-like sub-panel will be
     * created on long-click or mouse hover.
     *
     * @param view the view on which to set the tooltip text
     * @param tooltipText the tooltip text
     */
    public static void setTooltipText(@NonNull View view, @Nullable CharSequence tooltipText) {
        if (Build.VERSION.SDK_INT >= 26) {
            Api26Impl.setTooltipText(view, tooltipText);
        } else {
            TooltipCompatHandler.setTooltipText(view, tooltipText);
        }
    }

    private TooltipCompat() {
    }

    @RequiresApi(26)
    static class Api26Impl {
        private Api26Impl() {
            // This class is not instantiable.
        }

        @DoNotInline
        static void setTooltipText(View view, CharSequence tooltipText) {
            view.setTooltipText(tooltipText);
        }
    }
}