You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
58 lines
1.5 KiB
package com.community.pocket.ui.main;
|
|
|
|
import android.os.Build;
|
|
import android.view.View;
|
|
import android.widget.Button;
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
import androidx.navigation.NavController;
|
|
import androidx.navigation.Navigation;
|
|
|
|
import com.community.pocket.R;
|
|
import com.community.pocket.ui.BaseFragment;
|
|
|
|
/**
|
|
* 二级菜单基础框架
|
|
*/
|
|
public abstract class MainFragment extends BaseFragment {
|
|
|
|
/**
|
|
* @return FragmentContainerView id
|
|
*/
|
|
protected abstract int fragmentId();
|
|
|
|
private NavController navController;
|
|
|
|
/**
|
|
* @return 路由控制器
|
|
*/
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
protected NavController ctrl() {
|
|
if (navController == null && getView() != null) {
|
|
navController = Navigation.findNavController(getView().findViewById(fragmentId()));
|
|
}
|
|
return navController;
|
|
}
|
|
|
|
/**
|
|
* 点击按钮改变字体颜色
|
|
*/
|
|
protected void changeColor(View view) {
|
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
|
for (int id : buttonIds()) {
|
|
Button button = requireActivity().findViewById(id);
|
|
button.setTextAppearance(R.style.Button_unselect);
|
|
}
|
|
|
|
if (view instanceof Button) {
|
|
Button button = (Button) view;
|
|
button.setTextAppearance(R.style.Button_select);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 按钮组id
|
|
*/
|
|
protected abstract int[] buttonIds();
|
|
}
|
|
|