سؤال

I want to add a shadow and have rounded edges on my button, like box-shadow and border radius in CSS how can I do this in XML? XML code:

    <Button android:id="@+id/dummy_button"
    style="?metaButtonBarButtonStyle"
    android:layout_width="198dp"
    android:layout_height="69dp"
    android:layout_weight="1"
    android:text="@string/dummy_button"
    android:fontFamily="trebuchet ms"
    android:clickable="true"
    android:onClick="printStarter"
    android:background="#8c96ff"
    android:layout_gravity="center_horizontal|bottom" />
هل كانت مفيدة؟

المحلول

The Android Developer's Guide has a detailed guide on this: Shape Drawbables.

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="3dp" />
    <stroke android:width="5px" android:color="#1a1a1a" />

button with shadow

<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:drawable="@drawable/shadow"/>
   <item
     android:drawable="@drawable/button"
     android:bottom="4px" /> 

</layer-list>
    </shape>

Refer this tutorial

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top