像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布局引用
<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>
<?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) {
}
});
}
}