如何通过按下按钮在android中绘制圆圈? [英] How to draw circle in android by pressing a button?
本文介绍了如何通过按下按钮在android中绘制圆圈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在按下按钮的同时在屏幕上显示小点,例如 pin 代码......
I want to show small dots on screen while pressing a button, something like pin code...
switch (view.getId()){
case R.id.buttonNum1:
editor.putString("PinNumbers",getString(R.string.numberOne));
int x = 10;
int y = 30;
int r = 100;
Paint mPaint = new Paint();
mPaint.setColor(Color.BLACK);
Canvas mCanvas = new Canvas();
mCanvas.drawCircle(x,y,r,mPaint);
break;
推荐答案
你可以通过创建涟漪效果
You can achive by creating ripple effect
在drawable-v21文件夹中创建一个可绘制的名称,如pin_button_ripple,并添加以下代码
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"/>
你会看到涟漪效应我们通过键盘输入Pin
数字或密码并显示效果
You will see the ripple effect in circle shape like we enter Pin number or password via keyboard and showing that effect
这篇关于如何通过按下按钮在android中绘制圆圈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文