EditText评论按钮

像QQ输入框那样 监听输入类容变换发送按钮的效果。

Xml布局...
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:gravity="center"
              android:background="@color/comment"
              android:layout_width="match_parent"
              android:layout_height="100dp">
        <EditText android:id="@+id/EditText"
                  android:background="@drawable/edit"
                  android:layout_weight="1"
                  android:paddingLeft="5dp"
                  android:layout_marginLeft="10dp"
                  android:hint="请输入评语..."
                  android:textSize="13dp"
                  android:layout_width="match_parent"
                  android:layout_height="40dp"/>
        <LinearLayout android:gravity="center"
                      android:layout_width="50dp"
                      android:orientation="vertical"
                      android:layout_height="match_parent">
            <ImageView android:id="@+id/push"
                       android:background="@drawable/tongxun"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"/>

        </LinearLayout>
</LinearLayout>


 main布局引用

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:background="@color/white"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_weight="1">
        <ImageView android:layout_width="match_parent"
                   android:background="@drawable/ic_launcher"
                   android:layout_height="match_parent"/>
    </LinearLayout>

    <include layout="@layout/edittext">
    </include>

</LinearLayout>

然后是Java
package com.anan.EditTextDemo;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    private EditText mEdieText;
    private ImageView push;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setContentView(R.layout.main);
        initView();
    }

    public void initView() {
        push = (ImageView) findViewById(R.id.push);
        push.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MyActivity.this, "你点击了一头猪", 1500).show();
            }
        });
        mEdieText = (EditText) findViewById(R.id.EditText);
        mEdieText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            // s 为监听输入框字符串
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (s.length() > 0) {
                    push.setBackgroundResource(R.drawable.forwardfill);
                    push.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Toast.makeText(MyActivity.this, "你点击了发送按钮", 1500).show();
                            mEdieText.setText("");
                            push.setBackgroundResource(R.drawable.tongxun);
                        }
                    });
                } else {
                    push.setBackgroundResource(R.drawable.tongxun);
//                    mEdieText.clearFocus();
                    push.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Toast.makeText(MyActivity.this, "你点击了第二头猪", 1500).show();
                        }
                    });
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值