简体   繁体   中英

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
        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. 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.

This can be done by putting performClick() method invocation on the textview into button's onClick . Not sure if that's what you wanted.

This is a way to programmaticaly invoke a click on that textView. Code snapshot would like something like:

button.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v){
        textView.performClick();
    }
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM