Benutzer:MovGP0/Xamarin/Shaped Buttons

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


(Irrgegular) Shaped Buttons in Xamarin

[Bearbeiten | Quelltext bearbeiten]
  1. Implement a custom renderer

Provide button shapes

  1. res/drawable/mybutton_default.xml
  2. res/drawable/mybutton_focused.xml
  3. res/drawable/mybutton_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- see android.graphics.drawable.shapes.* for possible shapes -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <gradient android:angle="270" android:endColor="#4aae87" android:startColor="#FF4AAE87" />
    <corners android:radius="0dp" />
    <stroke android:width="2dp" android:color="#2a7e5d" />
</shape>

Use a selector to apply proper style based on button state in res/drawable/mybutton.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/mybutton_default" />
    <item android:drawable="@drawable/mybutton_focused" android:state_focused="true" />
    <item android:drawable="@drawable/mybutton_pressed" android:state_pressed="true" />
</selector>

Apply style to button:

<Button
    android:id="@+id/mybutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/button_text"
    android:onClick="onButtonClicked"
    android:background="@drawable/mybutton"  />

Add an ripple effect.[1]

render UIControl using custom renderer

react to touch events for animation

react to UIButtonState

Use a control template

DataBinding Options

[Bearbeiten | Quelltext bearbeiten]
  1. How to make a radial reaction. In: StackOverflow. 1. August 2015, abgerufen am 20. Januar 2017 (englisch, How to ipmlement a Ripple Effect in Android).