Giter VIP home page Giter VIP logo

tooltips's Introduction

Tooltips

Simple to use library for android, Enabling to add a tooltip near any view with ease

What's new

  • v 1.0.10 Added several APIs to allow complete customization of the tooltip view.
    • Replaced setTextColor() & setTextSize() with setTextAppearance() API for more control over tool tip view appearance. Also added setTypeface() API to allow custom font for tooltips view.
    • Updated ToolTip.Builder() API to accept CharSequence as tooltip message text to allow broader type of spannable messages.
    • Added ToolTipsManager.setToolTipAnimator() API to allow library consumer to customize the tooltip show and hide animation.
  • v 1.0.9 fix RTL support for arabic
  • v 1.0.8 fix dismiss all method
  • v 1.0.7 decrease min sdk to 14
  • v 1.0.6 add text size attribute to tooltip builder
  • v 1.0.5 remove conflicting application attributes
if you are looking for a more robust features check out https://github.com/tomergoldst/hoverview

Instructions

Add a dependency to your app build.gradle

dependencies {
    compile 'com.tomergoldst.android:tooltips:1.0.10'
}

Create a ToolTipsManager object

ToolTipsManager mToolTipsManager;
mToolTipsManager = new ToolTipsManager();

Use the ToolTip.Builder to construct your tip

ToolTip.Builder builder = new ToolTip.Builder(this, mTextView, mRootLayout, "Tip message", ToolTip.POSITION_ABOVE);

mTextView here is the view which near it the tip will be shown and mRootLayout is the layout where the tip view will be added to. The root layout must be of RelativeLayout, FrameLayout or similar. LinearLayout won't work but you can always wrap your LinearLayout with another layout. Prefer to pass in a layout which is higher in the xml tree as this will give the tip view more visible space.

OPTIONAL: Customize your tip with background color, text color, alignment, text gravity, type face and more.

builder.setAlign(ToolTip.ALIGN_LEFT);
builder.setBackgroundColor(getResources().getColor(R.color.colorOrange));
builder.setGravity(ToolTip.GRAVITY_RIGHT);
builder.setTextAppearance(R.style.TooltipTextAppearance); // from `styles.xml`
builder.setTypeface(mCustomFontTypeface);

Here is an example on how you can define your text appearance in your styles.xml

<style name="TooltipTextAppearance">
    <item name="android:textColor">@color/your_custom_color</item>
    <item name="android:textSize">16sp</item>
    <item name="android:textStyle">bold</item>
</style>

You can also customize the animation used to show and hide the tooltip view by providing ToolTipAnimator implementation and setting it in the ToolTipsManager.

mToolTipsManager = new ToolTipsManager(context);
mToolTipsManager.setToolTipAnimator(MyCustomToolTipAnimator());

Use ToolTipManger to show the tip

IMPORTANT: This must be called after the layout has been drawn You can override the onWindowFocusChanged() of an Activity and show there, Start a delayed runnable from onStart(), react to user action or any other method that works for you

mToolTipsManager.show(builder.build());

Each tip is dismissable by clicking on it, if you want to dismiss a tip from code there are a few options, the most simple way is to do the following

mToolTipsManager.findAndDismiss(mTextView);

Where mTextView is the same view we asked to position a tip near it

If you want to react when tip has been dismissed, Implement ToolTipsManager.TipListener interface and use appropriate ToolTipsManager constructor

public class MainActivity extends AppCompatActivity implements ToolTipsManager.TipListener
.
.
@Override
protected void onCreate(Bundle savedInstanceState) {
    mToolTipsManager = new ToolTipsManager(this);
}
.
.
@Override
public void onTipDismissed(View view, int anchorViewId, boolean byUser) {
    Log.d(TAG, "tip near anchor view " + anchorViewId + " dismissed");

    if (anchorViewId == R.id.text_view) {
        // Do something when a tip near view with id "R.id.text_view" has been dismissed
    }
}

License

Copyright 2016 Tomer Goldstein

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.

tooltips's People

Contributors

tomergoldst avatar hossain-khan avatar mhzdev avatar ravidsrk avatar cooperkong avatar jzeferino avatar

Watchers

James Cloos avatar Arindam Karmakar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.