简体   繁体   English

我想通过按一个按钮在Textview上产生波纹效果。 可能吗? 我该怎么做?

[英]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.

相关问题 按后退按钮时,我的“视频视图”为空白。 我该如何解决? - my "video view" is blank when pressing the back button. How i can fix it? 我想检查onClick按钮事件的蓝牙状态。 有可能这样做吗? 这是我的代码的一部分 - i want to check the bluetooth state on the event of onClick button. is it possible to do so? here are part of my code Java:单击按钮时,我想获取TextField值。 怎么做? - Java: I want to get TextField value when I clicked a button. How to do it? 我想通过在当前应用程序中按一个按钮来终止/关闭特定应用程序。 我怎样才能做到这一点? - I want to kill/ close a particular app by pressing a button in my current app. How can I do this? 如果输入正确,我怎样才能让(EditText)自动将用户发送到另一个页面? 无需按钮。 android 工作室 - How can I make the (EditText) automatically send the user to the other page if the input is correct? without need button. android Studio 如何在我希望的时间显示按钮? - How do I make my button display at the time I want it to? 我正在构建一个倒数计时器应用程序,它从按下按钮开始。 应用程序在按下按钮时崩溃 - I am building a Count Down Timer app, that starts on pushing the button. The app crashes on pressing the button 按下按钮使Textview可见 - Make Textview Visible by Pressing a Button Java/Unity/Android - 如何在按下按钮时触发键码事件? - Java/Unity/Android - How do I Make a keycode event triggered when pressing a button? 多次按下按钮时如何进行声音重叠? - How can I make a sound overlap when pressing a button multiple times?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM