/** * 设置AppBar和Toolbar */ private void setupAppBarAndToolbar() { //如果该应用运行在android 5.0以上设备,设置标题栏的z轴高度 if (mAppBar != null && Build.VERSION.SDK_INT > 21) { mAppBar.setElevation(10.6f); } //如果界面中有使用toolbar,则使用toolbar替代actionbar //默认不是使用NoActionBar主题,所以如果需要使用Toolbar,需要自定义NoActionBar主题后,在AndroidManifest.xml中对指定Activity设置theme // if (mToolbar != null) { // setSupportActionBar(mToolbar); // if (isToolbarCanBack()) { // ActionBar actionBar = getSupportActionBar(); // if (actionBar != null) { // actionBar.setDisplayHomeAsUpEnabled(true); // } // } // } mToolbarNavigation.setVisibility(isToolbarCanBack() ? View.VISIBLE : View.GONE); mToolbarDivision.setVisibility(isToolbarCanBack() ? View.VISIBLE : View.GONE); mToolbarNavigation.setOnClickListener(v -> onBackPressed()); mLlToolbarTitle.setPadding(isToolbarCanBack() ? 0 : 40, 0, 0, 0); }
/** * 设置AppBar和Toolbar */ private void setupAppBarAndToolbar() { //如果该应用运行在android 5.0以上设备,设置标题栏的z轴高度 if (mAppBar != null && Build.VERSION.SDK_INT > 21) { mAppBar.setElevation(10.6f); } //如果界面中有使用toolbar,则使用toolbar替代actionbar //默认不是使用NoActionBar主题,所以如果需要使用Toolbar,需要自定义NoActionBar主题后,在AndroidManifest.xml中对指定Activity设置theme // if (mToolbar != null) { // setSupportActionBar(mToolbar); // if (isToolbarCanBack()) { // ActionBar actionBar = getSupportActionBar(); // if (actionBar != null) { // actionBar.setDisplayHomeAsUpEnabled(true); // } // } // } mToolbarNavigation.setVisibility(isToolbarCanBack() ? View.VISIBLE : View.GONE); mToolbarDivision.setVisibility(isToolbarCanBack() ? View.VISIBLE : View.GONE); mToolbarNavigation.setOnClickListener(v -> onBackPressed()); mLlToolbarTitle.setPadding(isToolbarCanBack() ? 0 : 40, 0, 0, 0); }
/** * 设置Toolbar没阴影效果 */ public void setToolBarHasShade() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { appBar.setElevation(10); } }
/** * 设置Toolbar没阴影效果 */ public void setToolBarNoShade() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { appBar.setElevation(0); } }
private void setToolbarShadow(int id){ AppBarLayout appBar = findViewById(R.id.appBar); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP) { // If Community section is opened, the AppBarLayout should have no shadows // to prevent shadow overlapping with TabLayout if (id == R.id.nav_community) { appBar.setElevation(0); } else { appBar.setElevation(6); } } }
public void initBar() { if (mToolbar == null || mAppBar == null) { throw new IllegalStateException("no toolbar"); } setSupportActionBar(mToolbar); if (canBack()) { ActionBar actionBar = getSupportActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true); } if (Build.VERSION.SDK_INT >= 21) { mAppBar.setElevation(10.6f); } }
@Override protected void initToolbar(Bundle savedInstanceState) { if (this.mToolbar == null || this.mAppBarLayout == null) return; this.setSupportActionBar(mToolbar); this.mActionBarHelper = this.createActionBarHelper(); this.mActionBarHelper.init(); if (Build.VERSION.SDK_INT >= 21) { this.mAppBarLayout.setElevation(6.6f); } }
@Override public void initView() { if (mToolbar == null || mAppBar == null) { throw new IllegalStateException( "The subclass of ToolbarActivity must contain a toolbar."); } mToolbar.setOnClickListener(v -> onToolbarClick()); setSupportActionBar(mToolbar); if (canBack()) { ActionBar actionBar = getSupportActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true); } if (Build.VERSION.SDK_INT >= 21) { mAppBar.setElevation(10.6f); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPresenter = createPresenter(); mPresenter.attachView((V) this); setContentView(provideContentViewId());//布局 ButterKnife.bind(this); mAppBar = (AppBarLayout) findViewById(R.id.app_bar_layout); mToolbar = (Toolbar) findViewById(R.id.toolbar); if (mToolbar != null && mAppBar != null) { setSupportActionBar(mToolbar); //把Toolbar当做ActionBar给设置 if (canBack()) { ActionBar actionBar = getSupportActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);//设置ActionBar一个返回箭头,主界面没有,次级界面有 } if (Build.VERSION.SDK_INT >= 21) { mAppBar.setElevation(10.6f);//Z轴浮动 } } if(isSetRefresh()) { setupSwipeRefresh(); } }
public void setGamesFragment() { setTitle("Games"); getSupportActionBar().setSubtitle(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { appBarLayout.setElevation(0); } // Use new fragment instance so that the viewpager / dates are re-created. See #230. ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), GamesHomeFragment.Companion.newInstance(), R.id.fragment); expandToolbar(); selectedFragment = GAMES_FRAGMENT_ID; }
public void setHighlightsFragment() { setTitle("Highlights"); getSupportActionBar().setSubtitle(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { appBarLayout.setElevation(0); } Fragment highlightsFragment = null; if (selectedFragment == HIGHLIGHTS_FRAGMENT_ID) { highlightsFragment = getSupportFragmentManager().findFragmentById(R.id.fragment); if(!(highlightsFragment instanceof HighlightsMenuFragment)) { highlightsFragment = null; } } if (highlightsFragment == null) { highlightsFragment = HighlightsMenuFragment.Companion.newInstance(); ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), highlightsFragment, R.id.fragment); } expandToolbar(); selectedFragment = HIGHLIGHTS_FRAGMENT_ID; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //允许为空,不是所有都要实现MVP模式 if(createPresenter()!=null) { mPresenter = createPresenter(); mPresenter.attachView((V) this); } setContentView(provideContentViewId());//布局 ButterKnife.bind(this); mAppBar = findViewById(R.id.app_bar_layout); mToolbar = findViewById(R.id.toolbar); if (mToolbar != null && mAppBar != null) { setSupportActionBar(mToolbar); //把Toolbar当做ActionBar给设置 if (canBack()) { ActionBar actionBar = getSupportActionBar(); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true);//设置ActionBar一个返回箭头,主界面没有,次级界面有 } if (Build.VERSION.SDK_INT >= 21) { mAppBar.setElevation(10.6f);//Z轴浮动 } } if (isSetRefresh()) { setupSwipeRefresh(); } }
public void setPostsFragment(String subreddit) { setTitle("r/" + subreddit); getSupportActionBar().setSubtitle(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { appBarLayout.setElevation(UnitUtils.convertDpToPixel(4, this)); } Fragment postsFragment = null; if (selectedFragment == POSTS_FRAGMENT_ID) { postsFragment = getSupportFragmentManager().findFragmentById(R.id.fragment); if(!(postsFragment instanceof PostsFragment)) { postsFragment = null; } } if (postsFragment == null || !this.subreddit.equals(subreddit)) { postsRepository.clearCache(); postsFragment = PostsFragment.newInstance(subreddit); ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), postsFragment, R.id.fragment); } expandToolbar(); selectedFragment = POSTS_FRAGMENT_ID; this.subreddit = subreddit; }
public void setPlayoffsFragment() { setTitle("Playoff Bracket"); getSupportActionBar().setSubtitle(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { appBarLayout.setElevation(UnitUtils.convertDpToPixel(4, this)); } Fragment bracketFragment = null; if (selectedFragment == PLAYOFF_FRAGMENT_ID) { bracketFragment = getSupportFragmentManager().findFragmentById(R.id.fragment); if(!(bracketFragment instanceof BracketFragment)) { bracketFragment = null; } } if (bracketFragment == null) { bracketFragment = BracketFragment.Companion.newInstance(); ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), bracketFragment, R.id.fragment); } expandToolbar(); selectedFragment = PLAYOFF_FRAGMENT_ID; }
public void setStandingsFragment() { setTitle("Standings"); getSupportActionBar().setSubtitle(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { appBarLayout.setElevation(UnitUtils.convertDpToPixel(4, this)); } Fragment standingsFragment = null; if (selectedFragment == STANDINGS_FRAGMENT_ID) { standingsFragment = getSupportFragmentManager().findFragmentById(R.id.fragment); if(!(standingsFragment instanceof StandingsFragment)) { standingsFragment = null; } } if (standingsFragment == null) { standingsFragment = StandingsFragment.newInstance(); ActivityUtils.addFragmentToActivity(getSupportFragmentManager(), standingsFragment, R.id.fragment); } expandToolbar(); selectedFragment = STANDINGS_FRAGMENT_ID; }