我通过单击按钮显示设置框。我使用此代码:
<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);
}
谢谢
我会在匹配的父视图中包装设置框,当我显示"设置"框setOnClickListener时,该视图的setOnClickListener无需执行任何操作,以停止下方的任何单击。
<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>
和
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);
}