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.

60 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;
import java.util.Objects;
/**
* 二级菜单基础框架
*/
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;
}
/**
* 点击按钮改变字体颜色
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
protected void changeColor(View view) {
int color = getResources().getColor(R.color.button_unchecked);
for (int id : button_ids()) {
View v = Objects.requireNonNull(getActivity()).findViewById(id);
v.setBackgroundColor(color);
}
if (view instanceof Button) {
Button button = (Button) view;
button.setBackgroundColor(getResources().getColor(R.color.colorAccent));
}
}
/**
* 按钮组id
*/
protected abstract int[] button_ids();
}