我通过单击一个按钮来显示一个设置框。我使用这段代码:
<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>
“main_menu_buttons”中有按钮。如果设置框可见,我想禁用屏幕上的所有项目。现在,焦点可以从设置框转到 main_menu 的按钮。我不想要那个。有没有办法做到这一点,而无需逐一禁用每个项目?
这是显示/隐藏设置框的代码
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);
}
谢谢