質問

iPhoneのようなAndroid EditboxのX-Graphicsを追加する方法はありますか。

alt text

天気を聞く方法はありますか?編集テキストの特定の部分に触れてくれてありがとう

役に立ちましたか?

解決

はい、これを達成する方法があります。

このような関係を定義します。

<?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は編集の上に描画されます。右側に右端が右側に表示されるように設定します。

これで、Edittextsテキストをそのような空の文字列に設定するために、オーバーライドされたメソッドを備えた場合のOnClickListenerをImageButtonに割り当てる必要があります。

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("");
        }
});

}

ここでは、クリックのテキストをクリックすると、edicklistener onclicklistenerを把握してください。そのような単純な。 ;)

もちろん、私の例ではあまり美的画像ではありませんが、自分で画像を微調整することができます。原則は機能します。

他のヒント

ダウンロードできます。iPhoneのように機能します

https://github.com/ghosttt/edittextxbutton

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top