iPhoneのようにAndroidのエディットボックスにx-グラフィックを追加する方法はありますか?そのxグラフィックをクリックすることで、エディットボックスのすべての値をクリアできます
天気を聞く方法はありますか編集テキストの特定の部分に触れますありがとうございます
はい、これを達成する方法があります。
このような RelativeLayout を定義します。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<ImageButton android:id="@+id/clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_alignRight="@id/edittext"/>
</RelativeLayout>
さてどうなるか。ImageButton は、EditText の上に描画されます。右側に表示されるように、右端を EditTexts の右端と等しくなるように設定します。
EditTextsテキストをそのような空の文字列に設定するだけの場合、オーバーライドされたメソッドでImageButtonにOnClickListenerを割り当てる必要があります。
EditText editText = null;
ImageButton clear = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.clear);
editText = (EditText) findViewById(R.id.edittext);
clear = (ImageButton) findViewById(R.id.clear);
clear.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
editText.setText("");
}
});
}
ここでは、クリック時に EditTexts テキストをリセットするように ImageViews OnClickListener に指示するだけです。そのような単純な。;)
もちろん、私の例ではあまり美しい画像を使用していませんが、自分で画像を微調整することができます。原則は機能します。
あなたはそれをダウンロードすることができます、それはiPhoneのように動作します