###前提・実現したいこと
AndroidStudio2にて開発、対象のAndroidは5.0です。
全画面表示中にSpinnerを使用したい。全画面が解除されないようにする方法は有りますか?
###発生している問題・エラーメッセージ
全画面表示はできており、画面内にSpinnerを追加したところ、Spinnerを選択した瞬間に全画面表示が解除されてしまう。
エラーメッセージ
エラーは発生していません。
###該当のソースコード
package com.test.spinnertest; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); String[] arr = new String[]{"Item1", "Item2", "Item3"}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spiner_item, arr); adapter.setDropDownViewResource(R.layout.spiner_dropdown_item); Spinner spinner = (Spinner)findViewById(R.id.spinner); spinner.setAdapter(adapter); View decor = this.getWindow().getDecorView(); decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { View decor = getWindow().getDecorView(); decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); } }
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.test.spinnertest.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" android:id="@+id/textView" /> <Spinner android:id="@+id/spinner" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintHorizontal_bias="0.0" android:layout_marginTop="8dp" app:layout_constraintTop_toBottomOf="@+id/textView" /> </android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?> <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" style="?android:attr/spinnerItemStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="24sp" />
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" style="?android:attr/spinnerItemStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="24sp" android:ellipsize="marquee"/>
###試したこと
OnItemSelectedListenerを使用し、Itemが選択された後で再度全画面を指定することで全画面になりますが、Spinerを選択する際には全画面が解除されてしまう。
###補足情報(言語/FW/ツール等のバージョンなど)
AndroidStudio 2.3.3
あなたの回答
tips
プレビュー