0

I am new to android and I wish to achieve a tooltip with border. Tooltip pointing to left. i.e: like below with text of choice. enter image description here

please help me with this, stuck with this for quite sometime now.

I was able to create a tooltip at top righ but how to get it in left ceter_verticle like the diagram.

my code looks like.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:gravity="top|right" android:right="10dp">
        <rotate android:fromDegrees="45" android:toDegrees="0"
            android:pivotX="50%" android:pivotY="0%" >
            <shape android:shape="rectangle">
                <size android:width="24dp" android:height="24dp" />
                <stroke android:color="@android:color/holo_blue_bright" android:width="1dp"/>
            </shape>
        </rotate>
    </item>
    <item>
        <shape android:shape="rectangle">
            <size android:width="206dp" android:height="76dp" />
            <solid android:color="@color/white"/>
            <stroke android:color="@android:color/holo_blue_bright"  android:width="1dp"/>
            <corners android:radius="2dp" />
        </shape>
    </item>

    <item android:gravity="top|right" android:right="10dp" android:top="1dp">
        <rotate android:fromDegrees="45" android:toDegrees="0"
            android:pivotX="50%" android:pivotY="0%" >
            <shape android:shape="rectangle">
                <size android:width="24dp" android:height="24dp" />
                <solid android:color="@color/white"/>
            </shape>

        </rotate>
    </item>

</layer-list>

1 Answers1

1

Try the below code:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:left="16dp"
       android:right="16dp"
       android:top="17dp"
       android:bottom="17dp">
       <shape android:shape="rectangle">
           <solid android:color="#FFFFFF" />
           <corners android:radius="15dp" />
       </shape>
   </item>
   <item
       android:bottom="345dp"
       android:right="360dp"
       android:top="345dp">
       <rotate
           android:fromDegrees="-45"
           android:pivotX="10%"
           android:pivotY="10%"
           android:toDegrees="0">
           <shape android:shape="rectangle">
               <solid android:color="#FFFFFF" />
           </shape>
       </rotate>
   </item>
   <item
       android:bottom="350dp"
       android:right="350dp"
       android:top="350dp">
       <rotate
           android:fromDegrees="-45"
           android:pivotX="1%"
           android:pivotY="-5%"
           android:toDegrees="0">
           <shape android:shape="rectangle">
               <solid android:color="#000000" />
           </shape>
       </rotate>
   </item>
   <item
       android:bottom="19dp"
       android:left="19dp"
       android:right="19dp"
       android:top="19dp">
       <shape android:shape="rectangle">
           <solid android:color="#000000" />
           <corners android:radius="15dp" />
       </shape>
   </item>
</layer-list>
Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80
  • I was trying to use this in a text view, with height 70dp and width 200dp it renders a round box rather than tooltip. is it because the tooltip has bigger dimensions and thats why not working for smaller dimensions? I tried to change dimensions of tooltip but that distorts shape. – someonetonobody Aug 11 '21 at 06:34
  • if you have time, can you please look at this? – someonetonobody Aug 11 '21 at 19:12