1

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.

A.munziR
  • 21
  • 2

1 Answers1

0

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();
    }
};
Vucko
  • 7,000
  • 2
  • 21
  • 42
  • 1
    This method can invoke but there is no physical change in that Text view. There is no ripple effect acted. Another solution? – A.munziR Jan 31 '18 at 14:30
  • No idea seriously... Thought this would do it. – Vucko Jan 31 '18 at 20:39
  • 2
    `View::performClick()` just fires `onClickListener` - it doesn't simulate touching that view. The `performClick` method doesn't know the point you want it to press and the lenght of the press action. You would have to dispatch touch events to really 'click' a view. See: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.0_r1/android/view/View.java#2359 – Zielony Feb 06 '18 at 09:00
  • I suspected as much. You're right. Thanks for the clarification man. – Vucko Feb 06 '18 at 16:05