在drawable中绘制工具提示

时间:2016-09-22 13:04:41

标签: android drawable shape

我想将工具提示添加到我的按钮。有没有简单的方法来做到这一点。我想绘制形状。但我只找到带有绘图视图的方法或建议添加lib。 是否可以绘制工具提示(使用xml制作工具提示)?

2 个答案:

答案 0 :(得分:6)

<?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>

答案 1 :(得分:3)

将宽度和高度插入size标记,以便在较低的API级别中使用:

<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>