public void showHint() {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);
    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    int referenceX = screenPos[0] + width / 2;
    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
      referenceX = screenWidth - referenceX; // mirror
    }
    StringBuilder hint = new StringBuilder("#");
    if (Color.alpha(color) != 255) {
      hint.append(Integer.toHexString(color).toUpperCase(Locale.ENGLISH));
    } else {
      hint.append(String.format("%06X", 0xFFFFFF & color).toUpperCase(Locale.ENGLISH));
    }
    Toast cheatSheet = Toast.makeText(context, hint.toString(), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
      // Show along the top; follow action buttons
      cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top);
    } else {
      // Show along the bottom center
      cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
  }
public void showHint ( ) { final int [ ] screenPos = new int [ 2 ] ; final Rect displayFrame = new Rect ( ) ; getLocationOnScreen ( screenPos ) ; getWindowVisibleDisplayFrame ( displayFrame ) ; final Context context = getContext ( ) ; final int width = getWidth ( ) ; final int height = getHeight ( ) ; final int midy = screenPos [ 1 ] + height / 2 ; int referenceX = screenPos [ 0 ] + width / 2 ; if ( ViewCompat . getLayoutDirection ( this ) == ViewCompat . LAYOUT_DIRECTION_LTR ) { final int screenWidth = context . getResources ( ) . getDisplayMetrics ( ) . widthPixels ; referenceX = screenWidth - referenceX ; } StringBuilder hint = new StringBuilder ( "#" ) ; if ( Color . alpha ( color ) != 255 ) { hint . append ( Integer . toHexString ( color ) . toUpperCase ( Locale . ENGLISH ) ) ; } else { hint . append ( String . format ( "%06X" , 0xFFFFFF & color ) . toUpperCase ( Locale . ENGLISH ) ) ; } Toast cheatSheet = Toast . makeText ( context , hint . toString ( ) , Toast . LENGTH_SHORT ) ; if ( midy < displayFrame . height ( ) ) { cheatSheet . setGravity ( Gravity . TOP | GravityCompat . END , referenceX , screenPos [ 1 ] + height - displayFrame . top ) ; } else { cheatSheet . setGravity ( Gravity . BOTTOM | Gravity . CENTER_HORIZONTAL , 0 , height ) ; } cheatSheet . show ( ) ; }
Show a toast message with the hex color code below the view.