簡體   English   中英

我想通過按一個按鈕在Textview上產生波紋效果。 可能嗎? 我該怎么做?

[英]I want to make Ripple effect on Textview by pressing a button. Is it possible? How can I do it?

這是我的波紋效果代碼:

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

和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" />

當Textview觸摸時創建的波紋效果,但是我想通過按一個按鈕來創建。 可能嗎? 如果可能的話我該怎么辦?

這是該按鈕的代碼:

         <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" />

按鈕處理程序代碼為:

 buttonClear.setOnClickListener(
            new Button.OnClickListener() {
                public void onClick(View v) {


                    input.setText(null);
                    output.setText("output");

                }
            }
    );

我希望通過按此按鈕,波紋效果將出現在Textview上。

這可以通過將textview上的performClick()方法調用放入button的onClick 不確定這是否是您想要的。

這是一種以編程方式調用該textView的單擊的方法。 代碼快照將類似於:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM