@Override public void onBackPressed() { if (sv_bottom_content.getVisibility() == View.VISIBLE) { doReverseAnimation(); } else { super.onBackPressed(); } }
@Override public void onCreate(Bundle savedInstanceState) { // 如果系统的主题为Activity_translucent_navigation_bar,但是手机没有navigation bar,则将其设置回status bar主题, // setTheme设置主题一定要在onCreate()之前 if (!CommonUtils.hasNavigationBar() && getApplicationInfo().theme == R.style.Activity_translucent_navigation_bar) { setTheme(R.style.Activity_translucent_status_bar); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_base_layout); fl_top_bar = (FrameLayout) findViewById(R.id.fl_top_bar); base_content = (FrameLayout) findViewById(R.id.base_content); sv_bottom_content = (ScrollView) findViewById(R.id.sv_bottom_content); ll_bottom_content = (LinearLayout) findViewById(R.id.ll_bottom_content); ll_full_screen = findViewById(R.id.ll_full_screen); ll_full_screen.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { doReverseAnimation(); } }); // SDK19版本以上 if (Build.VERSION.SDK_INT >= 19 && (getApplicationInfo().theme == R.style.Activity_translucent_status_bar || getApplicationInfo().theme == R.style.Activity_translucent_navigation_bar)) { v_status_bar = findViewById(R.id.v_status_bar); v_navigation_bar = findViewById(R.id.v_navigation_bar); v_status_bar.setVisibility(View.VISIBLE); v_navigation_bar.setVisibility(View.VISIBLE); int id = getResources().getIdentifier("status_bar_height", "dimen", "android"); v_status_bar.getLayoutParams().height = getResources().getDimensionPixelOffset(id); // 如果手机有navigation bar if (CommonUtils.hasNavigationBar()) { isUsingNavigation = (getApplicationInfo().theme == R.style.Activity_translucent_navigation_bar); // 底部navigation bar透明风格 if (isUsingNavigation) { id = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); v_navigation_bar.getLayoutParams().height = getResources().getDimensionPixelOffset(id); } } else { v_navigation_bar.setVisibility(View.GONE); v_navigation_bar = null; } } // 添加top bar,现在有两种样式的top bar可以使用: // 一种是自定的viewGroup,比如QQ if (!useToolbar) { top_bar = (ViewGroup) View.inflate(this, R.layout.activity_top_bar_layout, null); View rl_back = top_bar.findViewById(R.id.rl_back); rl_back.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); TextView tv_title = (TextView) top_bar.findViewById(R.id.tv_title); // 通过 android::label 设置的标题 if (!TextUtils.isEmpty(getTitle())) tv_title.setText(getTitle()); } // 一种是使用系统控件toolbar,比如微信 else { top_bar = (ViewGroup) View.inflate(this, R.layout.activity_top_toolbar_layout, null); Toolbar toolbar = (Toolbar) top_bar; setSupportActionBar(toolbar); toolbar.setTitleTextAppearance(this, R.style.toolbar_title_appearance); toolbar.setTitleTextColor(getResources().getColor(R.color.white)); toolbar.setNavigationIcon(R.mipmap.ic_arrow_back); toolbar.setNavigationOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); // 通过 android::label 设置的标题 if (!TextUtils.isEmpty(getTitle())) toolbar.setTitle(getTitle()); } fl_top_bar.addView(top_bar); bottomItems = new LinkedHashMap<>(); inflater = LayoutInflater.from(this); initView(); initData(); }