HOME技術AndroidAndroidアプリ:フォーカスをあてたEditTextのテキストを全選択する

Androidアプリ:フォーカスをあてたEditTextのテキストを全選択する

Android StudioでEditTextにフォーカスが当たったと同時に、既に入力されている文字列をすべて選択した状態にする方法です。

EditTextタグに以下のコードを追加

android:selectAllOnFocus=”true”

上のコードをEditTextに追加すると、フォーカスが当たったときに既存のテキストを全選択した状態になります。
コード全体は以下のようになります。

<EditText
android:id=”@+id/editText”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:selectAllOnFocus=”true” />

関連記事

Androidアプリ:タイトルバーを消す

Android Studioで、タイトルバーを消す方法です。 通常は、以下のように画面上部にタイトルバーが表示されています。 AndroidManifest.xmlを編集する android:them…続きを読む

Androidアプリ:ボタンのテキストを変える

Androidでボタンのテキストをプログラム上で変える方法です。 MainActivity.java   Button button = findViewById(R.id.button);…続きを読む

Androidアプリ:内部テスト版をリリースする

Androidアプリで完成したものをすぐに公開する前に、内部テスト版としてリリースして動作確認をする方法です。 内部テスト版リリース方法 Google Play Consoleにログインして、「すべて…続きを読む

Androidアプリ:ClassNotFoundExceptionエラー

Google Play Consoleのクラッシュ報告で、「ClassNotFoundException(ac.loadClass)」というログが表示されていたので、調べました。 恐らくAdmobのS…続きを読む

Androidアプリ:ERROR: This project uses AndroidX dependencies, but the ‘android.useAndroidX’ property is not enabled.

Android Studioでビルドしようとしたら、「ERROR: This project uses AndroidX dependencies, but the ‘android.us…続きを読む

Androidアプリ:ボタンをタップして別画面に遷移する

ボタンをタップしたら別画面に遷移させる方法です。 以下の例では、メイン画面の「ボタン」をクリックすると、サブ画面に移動し、サブ画面の「終了」ボタンを押すとメイン画面に戻ってきます。 メイン画面 act…続きを読む

Androidアプリ:エラー「ScrollView can host only one direct child」

Android StudioでScrollViewを設定して動作確認しようとすると、「ScrollView can host only one direct child」というエラーが出て動作確認でき…続きを読む

Androidアプリ:ボタンやEditTextに余白(パディング)を設定する

Android StudioでボタンやEditTextに余白(パディング)を設定します。 余白の設定はレイアウトファイル(activity_main.xml)を編集します。 activity_main…続きを読む

Androidアプリ:App is not indexable by Google Search;と表示される

Android Studioで、 App is not indexable by Google Search; consider adding at least one Activity with a…続きを読む

Google広告でポリシー違反「句読点と記号」に対応する

モバイルアプリのGoogle広告のキャンペーンを設定しましたが、「ポリシー違反1件」と表示されました。 ポリシー違反「句読点と記号」 ポリシー違反の詳細を見ると、「句読点と記号」というヒントが表示され…続きを読む

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny