How to draw circle in android by pressing a button?

前端 未结 1 451
無奈伤痛
無奈伤痛 2021-01-26 11:37

I want to show small dots on screen while pressing a button, something like pin code...

switch (view.getId()){
    case R.id.buttonNum1:
               


        
相关标签:
1条回答
  • 2021-01-26 12:33

    You can achive by creating ripple effect

    create one drawable name like pin_button_ripple in drawable-v21 folder and add bellow code

    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
            android:color="?android:colorControlHighlight">
        <item android:id="@android:id/mask">
            <shape android:shape="oval">
                <solid android:color="?android:colorPrimary" />
    
            </shape>
        </item>
    </ripple>
    

    Now in Layout file set it as a background of button and define click listener in activity

    <Button
        android:id="@+id/btnPinButton"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        android:background="@drawable/pin_button_ripple"
        android:padding="20dp"
        android:text="10"/>
    

    You will see the ripple effect in circle shape like we enter Pin number or password via keyboard and showing that effect

    0 讨论(0)
提交回复
热议问题