HOME技術AndroidAndroidアプリ:ボタンの表示/非表示

Androidアプリ:ボタンの表示/非表示

Androidでボタンの表示/非表示をプログラム上からコントロールします。

MainActivity.java

 

Button button = findViewById(R.id.button);
button.setVisibility(View.VISIBLE); // 表示する場合
button.setVisibility(View.INVISIBLE); // 非表示にする場合

なお、buttonという名前のボタンがactivity_main.xmlで配置しているものとします。

関連記事

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

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

Androidアプリ:数値型のViewの値がNullか0以下かを判定する

Android Studioで数値型のEditTextのViewを配置して、値を取得した場合に、その値がNull値(空)もしくは0以下であるか否かを判定する方法です。 Null判定にlength()を…続きを読む

Androidアプリ:Android StudioでデバッグしようとするとPlease select Android SDKと表示される

Android Studioを使っていて、動作確認するために実行(run)をすると、ADVが起動せず、「Error: Please select Android SDK」と表示されてしまった場合の復旧…続きを読む

Androidアプリを実機で確認する

AndroidアプリをAndroid Studioで開発した際に、実際のスマホの画面で動作確認する方法です。 スマホの設定 以下はArrows FX F-02Hの設定方法です(開発者向けオプションを表…続きを読む

Androidアプリ:Class ‘Anonymous class derived from OnItemClickListener’…のエラー

Android Studioで開発中に、ListViewを使っていて以下のようなエラーメッセージが出た場合の理由です。 Class ‘Anonymous class derived from OnIt…続きを読む

Androidアプリ:error: expected color reference but got (raw string)

Android Studioでビルドした際に、C:\android\project\***\app\src\main\res\values\styles.xml: AAPT: error: expec…続きを読む

Androidアプリ:String型の変数に格納した画像や音声ファイル名から表示・再生する

Android Studioを使って画像ファイル名や音声ファイル名から、ImageViewで画像を表示したりMediaPlayerで音声再生する方法です。 String型の変数に、画像ファイル名もしく…続きを読む

Androidアプリ:android:fullBackupContentの宣言

Android Studioで、以下のようなエラーメッセージが表示されました。 On SDK version 23 and up, your app data will be automaticall…続きを読む

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アプリ:背景に画像を指定する

Android Studioを使って、背景に画像を設定する方法です。 背景画像を格納する 今回は以下の画像を使います。 画像サイズなどは適当につくります。 Androidは様々な解像度がありますが、画…続きを読む

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