[英]I want to make Ripple effect on Textview by pressing a button. Is it possible? How can I do it?
This is my code for ripple effect: 这是我的波纹效果代码:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@color/button_layout_ropple"
tools:targetApi="lollipop">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/button_layout_ropple" />
</shape>
</item>
</ripple>
and Textview xml code is: 和Textview xml代码是:
<TextView
android:layout_width="match_parent"
android:id="@+id/output"
android:textSize="20sp"
android:foreground="@drawable/ripple_effect"
android:background="#f4de97"
android:text="Result"
android:layout_height="65dp"
android:clickable="true" />
Ripple effect created when the Textview touched but I want to create this by pressing a button. 当Textview触摸时创建的波纹效果,但是我想通过按一个按钮来创建。 Is it possible?
可能吗? If possible how can I do it?
如果可能的话我该怎么办?
Here is the code of that button: 这是该按钮的代码:
<Button
android:id="@+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="clear"
android:background="#ECEFF1"
android:textColor="#000000"
android:textSize="20dp" />
button handler code is: 按钮处理程序代码为:
buttonClear.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
input.setText(null);
output.setText("output");
}
}
);
I want ripple effect will appear on Textview by pressing this button. 我希望通过按此按钮,波纹效果将出现在Textview上。
This can be done by putting performClick()
method invocation on the textview into button's onClick
. 这可以通过将textview上的
performClick()
方法调用放入button的onClick
。 Not sure if that's what you wanted. 不确定这是否是您想要的。
This is a way to programmaticaly invoke a click on that textView. 这是一种以编程方式调用该textView的单击的方法。 Code snapshot would like something like:
代码快照将类似于:
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
textView.performClick();
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.