Butterfly
Butterfly

Reputation: 455

Draw tooltip in drawable

I want to add tooltip up to my button. Is there any easy way to do this. I want to draw shape. But I only find methods with draw view or suggest to add lib. Is it possible to draw tooltip(make tooltip with xml)?

Upvotes: 3

Views: 5677

Answers (3)

Rupa
Rupa

Reputation: 7

<item
    android:top="17dp">

    <shape
        android:shape="rectangle">

        <solid
            android:color="#FF7276" />

        <corners
            android:radius="8dp" />

        <padding
            android:top="17dp" />

    </shape>

</item>

<item
    android:width="24dp"
    android:height="24dp"
    android:end="32dp"
    android:gravity="end"
    android:top="-12dp">

    <rotate
        android:fromDegrees="45">

        <shape
            android:shape="rectangle">

            <solid
                android:color="#FF7276" />

        </shape>

    </rotate>

</item>

Try this, you will get perfect Tooltip shape in UI, after coping this code just check your UI(xml) or run the the program

enter image description here

Upvotes: -1

Elior B.Y.
Elior B.Y.

Reputation: 301

insert the width and height into a size tag so it will be usable in lower API levels:

<item android:gravity="bottom|center_horizontal">

    <rotate android:fromDegrees="45" android:toDegrees="45"
        android:pivotX="50%" android:pivotY="50%" >

        <shape android:shape="rectangle">

            <size android:width="12dp" android:height="12dp" />

            <corners android:bottomRightRadius="2dp"/>

            <gradient android:type="linear"
                android:angle="0"
                android:endColor="@color/gradient_red"
                android:startColor="@color/gradient_red" />

        </shape>

    </rotate>

</item>

<item android:bottom="6dp">

    <shape android:shape="rectangle">

        <size android:width="120dp" android:height="36dp" />

        <gradient android:type="linear"
            android:angle="0"
            android:endColor="@color/gradient_red"
            android:startColor="@color/gradient_red" />

        <corners android:radius="6dp" />

    </shape>

</item>

Upvotes: 6

Butterfly
Butterfly

Reputation: 455

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

   <item
       android:width="12dp"
       android:height="12dp"
       android:gravity="bottom|center_horizontal">
       <rotate
           android:fromDegrees="45"
           android:pivotX="50%"
           android:pivotY="50%"
           android:toDegrees="45">
           <shape android:shape="rectangle">

               <corners android:bottomRightRadius="2dp"/>

               <gradient
                   android:angle="0"
                   android:endColor="#cc00b8 "
                   android:startColor="#ef89ff "
                   android:type="linear" />
           </shape>

       </rotate>
   </item>

   <item
       android:width="120dp"
       android:height="36dp"
       android:bottom="6dp">
       <shape android:shape="rectangle">

           <gradient
               android:angle="0"
               android:endColor="#cc00b8 "
               android:startColor="#ef89ff "
               android:type="linear" />

           <corners android:radius="6dp" />

       </shape>

   </item>


</layer-list>

Upvotes: 15

Related Questions