[英]Best way to make a “glowing” button in android java?
I am using Android Java in Android Studio with this project.我在这个项目的 Android Studio 中使用 Android Java。 I am trying to make a pulsating shadow for my button.我试图为我的按钮制作一个脉动的阴影。 I want it so whenever the user clicks the wrong button, I bring attention to the button they should click by making pulsating a shadow.我想要它,所以每当用户点击错误的按钮时,我都会通过制作脉动阴影来引起他们应该点击的按钮的注意。 I have looked through many forums and posts with no success.我浏览了许多论坛和帖子,但都没有成功。 If there is a different way to do this, please let me know.如果有其他方法可以做到这一点,请告诉我。 Thanks!谢谢!
EDIT: Here's some code I was working on:编辑:这是我正在处理的一些代码:
newTimerTask = new TimerTask() {
@Override
public void run() {
ObjectAnimator colorFade = ObjectAnimator.ofObject(start_stop_btn, "background", new ArgbEvaluator(), R.drawable.button_shadow, 0xff000000);
colorFade.setDuration(7000);
colorFade.start();
start_stop_btn.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.button_shadow);
}
};
Timer newTimer = new Timer();
newTimer.schedule(newTimerTask, 0, 100);
button_shadow.xml button_shadow.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#D6D6D6" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#E6E600" android:startColor="#FFFF00" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
Thanks in advance!提前致谢!
There is no such attribute in Android
, to show a shadow. Android
没有这样的属性,用来显示阴影。 You can do a work around like this :你可以做这样的工作:
Take LinearLayout
or Framelayout
with grey color, under your Button
, with margin
at bottom and right equal to 1 or 2 dp
.在Button
Framelayout
采用灰色的LinearLayout
或Framelayout
,底部和右侧的margin
等于 1 或 2 dp
。
Make it visible when wrong Button
is clicked.单击错误的Button
时使其可见。
Thats the best I can suggest for your requirement.这是我可以为您的要求提出的最好建议。
My suggestion is to get a good animation to catch user attention though.我的建议是制作一个好的动画来吸引用户的注意力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.