Reputation: 463
I show a settings box by clicking on a button. I use this code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="be.mforgetngroup.radioplayer.MainMenuFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/main_menu_buttons">
</LinearLayout>
<RelativeLayout android:id="@+id/settings_box"
style="@style/settings_box">
<LinearLayout style="@style/settings">
<TextView
android:text="@string/settings"
style="@style/settings_title" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end">
<RadioButton
android:text="@string/dark_theme"
style="@style/settings_options" />
<RadioButton
android:text="@string/light_theme"
style="@style/settings_options"/>
</RadioGroup>
</LinearLayout>
</RelativeLayout>
<ImageButton
android:id="@+id/settings_button"
style="@style/settings_button" />
</RelativeLayout>
There is buttons in "main_menu_buttons". I want to disable all items of the screen except the settings box if this one is visible. Now, the focus can go from the settings box to the buttons of the main_menu. I don't want that. Is there a way to do that without disable each item one by one ?
Here is the code to show/hide the settings box
View settingsBox = getView().findViewById(R.id.settings_box);
if(settingsBox.getVisibility() == View.GONE){
settingsBox.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.fade_in));
settingsBox.setVisibility(View.VISIBLE);
}
else{
settingsBox.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out));
settingsBox.setVisibility(View.GONE);
}
Thanks
Upvotes: 1
Views: 807
Reputation: 969
I would wrap the Settings box in a match parent view and when I show the settings box setOnClickListener of that view to do nothing that will stop any click below it.
<RelativeLayout android:id="@+id/stop_clicks"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:id="@+id/settings_box"
style="@style/settings_box"
centerInParent="true">
<LinearLayout style="@style/settings">
<TextView
android:text="@string/settings"
style="@style/settings_title" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end">
<RadioButton
android:text="@string/dark_theme"
style="@style/settings_options" />
<RadioButton
android:text="@string/light_theme"
style="@style/settings_options"/>
</RadioGroup>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
and
View settingsBox = getView().findViewById(R.id.settings_box);
View stopClicks = getView().findViewById(R.id.stop_clicks);
if(settingsBox.getVisibility() == View.GONE){
settingsBox.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.fade_in));
settingsBox.setVisibility(View.VISIBLE);
stopClicks.setVisibility(View.VISIBLE);
stopClicks.setOnClickListener(v -> null);
}
else{
settingsBox.startAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out));
settingsBox.setVisibility(View.GONE);
stopClicks.setVisibility(View.GONE);
stopClicks.setOnClickListener(null);
}
Upvotes: 1