Java Code Examples for android.support.v7.app.AppCompatActivity#setSupportActionBar()
The following examples show how to use
android.support.v7.app.AppCompatActivity#setSupportActionBar() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: M3u8VideoIView.java From MeiZiNews with MIT License | 6 votes |
private void initToolbar(final AppCompatActivity appCompatActivity) { toolbar.setTitle(appCompatActivity.getIntent().getStringExtra("title")); appCompatActivity.setSupportActionBar(toolbar); if (appCompatActivity.getSupportActionBar() == null) { return; } appCompatActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(appCompatActivity); } }); }
Example 2
Source File: AndroidUtils.java From go-bees with GNU General Public License v3.0 | 6 votes |
/** * Setup toolbar. * * @param act current activity. * @param isHome if it is home activity. * @param title title. * @return ActionBar. */ public static ActionBar setUpToolbar(AppCompatActivity act, boolean isHome, int title) { Toolbar toolbar = (Toolbar) act.findViewById(R.id.toolbar); act.setSupportActionBar(toolbar); ActionBar ab = act.getSupportActionBar(); if (ab != null) { ab.setDisplayHomeAsUpEnabled(true); if (isHome) { ab.setHomeAsUpIndicator(R.drawable.ic_menu); ab.setDisplayShowTitleEnabled(false); } else { ab.setDisplayShowHomeEnabled(true); } if (title != -1) { ab.setTitle(R.string.about_title); } } return ab; }
Example 3
Source File: WeatherFragment.java From AndroidSchool with Apache License 2.0 | 6 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_weather, container, false); ButterKnife.bind(this, root); AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.setSupportActionBar(mToolbar); if (activity.getSupportActionBar() != null) { activity.getSupportActionBar().setTitle(""); } mToolbarTitle.setText(getString(R.string.default_city)); mLoadingView = LoadingDialog.view(getFragmentManager()); return root; }
Example 4
Source File: PhotoDetailIView.java From MeiZiNews with MIT License | 6 votes |
private void initToolbar(final AppCompatActivity appCompatActivity) { appCompatActivity.setSupportActionBar(toolbar); if (appCompatActivity.getSupportActionBar() == null) { return; } appCompatActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); // [android:ToolBar详解(手把手教程)](http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1118/2006.html) toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { appCompatActivity.finishAfterTransition(); } else { appCompatActivity.finish(); } } }); }
Example 5
Source File: XmTvClassificationIView.java From MeiZiNews with MIT License | 6 votes |
private void initToolbar(final AppCompatActivity appCompatActivity) { toolbar.setTitle(appCompatActivity.getIntent().getStringExtra("title")); appCompatActivity.setSupportActionBar(toolbar); if (appCompatActivity.getSupportActionBar() == null) { return; } appCompatActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); // [android:ToolBar详解(手把手教程)](http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1118/2006.html) toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onBackPressed(appCompatActivity); } }); }
Example 6
Source File: SessionDetailFragment.java From droidkaigi2016 with Apache License 2.0 | 5 votes |
private void initToolbar() { AppCompatActivity activity = ((AppCompatActivity) getActivity()); activity.setSupportActionBar(binding.toolbar); ActionBar bar = activity.getSupportActionBar(); if (bar != null) { bar.setDisplayHomeAsUpEnabled(true); bar.setDisplayShowHomeEnabled(true); bar.setDisplayShowTitleEnabled(false); bar.setHomeButtonEnabled(true); } }
Example 7
Source File: ConditionalAlbumListFragment.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); albumArt = view.findViewById(R.id.albumArt); albumArtDim = view.findViewById(R.id.albumArtDim); appBar = view.findViewById(R.id.appBar); errorContainer = view.findViewById(R.id.errorContainer); emptyContainer = view.findViewById(R.id.emptyContainer); progress = view.findViewById(R.id.progress); fab = view.findViewById(R.id.fab); fab.setOnClickListener(v -> onFabClick()); final AppCompatActivity activity = (AppCompatActivity) getActivity(); if (activity == null) { throw new IllegalStateException("Activity is null"); } activity.setSupportActionBar(view.findViewById(R.id.toolbar)); recyclerView = view.findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(activity) { @Override public void onLayoutChildren(final RecyclerView.Recycler recycler, final RecyclerView.State state) { super.onLayoutChildren(recycler, state); setAppBarCollapsibleIfNeeded(); } }); if (TransitionUtils.supportsActivityTransitions()) { final View cardView = view.findViewById(R.id.cardView); LollipopUtils.applyTransitions((BaseActivity) activity, cardView != null); } }
Example 8
Source File: NewsDetailFragment.java From ZhihuDailyFluxRRD with Apache License 2.0 | 5 votes |
/** * 初始化 */ private void init() { AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.setSupportActionBar(mToolbar); ActionBar actionBar = activity.getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } mTvLoadError.setOnClickListener(this); setHasOptionsMenu(true); mNestedScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER); mWvNews.setOverScrollMode(View.OVER_SCROLL_NEVER); mWvNews.getSettings().setLoadsImagesAutomatically(true); //设置 缓存模式 mWvNews.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); // 开启 DOM storage API 功能 mWvNews.getSettings().setDomStorageEnabled(true); //为可折叠toolbar设置标题 mCollapsingToolbarLayout.setTitle(getString(R.string.app_name)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mNestedScrollView.setElevation(0); mWvNews.setElevation(0); } }
Example 9
Source File: BaseFragment.java From oneHookLibraryAndroid with Apache License 2.0 | 5 votes |
@Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final Toolbar toolbar = view.findViewById(R.id.id_common_toolbar); if(toolbar != null) { final AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.setSupportActionBar(toolbar); onToolbarReady(toolbar); } }
Example 10
Source File: BaseFragment.java From AndroidMaterialDesign with Apache License 2.0 | 5 votes |
protected void showHome(View view) { Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); if (toolbar != null) { AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.setSupportActionBar(toolbar); activity.getSupportActionBar().setDisplayShowHomeEnabled(true); } }
Example 11
Source File: AbstractSubsequentActivity.java From ShaderEditor with MIT License | 5 votes |
public static void initToolbar(AppCompatActivity activity) { Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar); activity.setSupportActionBar(toolbar); ActionBar actionBar = activity.getSupportActionBar(); if (actionBar == null) { return; } actionBar.setDisplayHomeAsUpEnabled(true); }
Example 12
Source File: DailyGankFragment.java From GankLock with GNU General Public License v3.0 | 5 votes |
@Override protected void initView() { mActivity = (AppCompatActivity) mContext; mToolbar = mContext.findViewById(R.id.toolbar_daily_fragment); mActivity.setSupportActionBar(mToolbar); mActivity.setTitle(R.string.bottom_bar_gank); mToolbar.inflateMenu(R.menu.main_menu); mRecyclerView = mContext.findViewById(R.id.daily_recycler_view); LinearLayoutManager manager = new LinearLayoutManager(mContext); manager.setOrientation(LinearLayoutManager.HORIZONTAL); mRecyclerView.setLayoutManager(manager); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); mSnapHelper = new LinearSnapHelper(); if (mRecyclerView.getOnFlingListener() == null) { mSnapHelper.attachToRecyclerView(mRecyclerView); } mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); int totalItemCount = layoutManager.getItemCount(); int lastVisibleItem = layoutManager.findLastVisibleItemPosition(); if (totalItemCount <= lastVisibleItem + 1) { loadDailyData(mPage+=1); } } }); mProgressBar = mContext.findViewById(R.id.daily_loading_progress_bar); mFailureTextView = mContext.findViewById(R.id.daily_get_failure_tip); }
Example 13
Source File: BaseFragment.java From NetEasyNews with GNU General Public License v3.0 | 5 votes |
/** * 设置toolbar标题居中,没有返回键 * @param view * @param id toolbar的id * @param titleId textView的id * @param titleString textView设置的文字 * @return 返回toolbar */ public Toolbar initToolbar(View view, int id, int titleId, int titleString) { Toolbar toolbar = (Toolbar) view.findViewById(id); // toolbar.setTitle(""); TextView textView = (TextView) view.findViewById(titleId); textView.setText(titleString); AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.setSupportActionBar(toolbar); android.support.v7.app.ActionBar actionBar = activity.getSupportActionBar(); if (actionBar != null){ actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } return toolbar; }
Example 14
Source File: SummaryView.java From px-android with MIT License | 5 votes |
public void configureToolbar(@NonNull final AppCompatActivity activity, @NonNull final View.OnClickListener listener) { final Toolbar toolbar = findViewById(R.id.toolbar); activity.setSupportActionBar(toolbar); final ActionBar actionBar = activity.getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayShowTitleEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setHomeButtonEnabled(true); actionBar.setHomeActionContentDescription(R.string.px_label_back); } toolbar.setNavigationOnClickListener(listener); }
Example 15
Source File: OAppBarUtils.java From framework with GNU Affero General Public License v3.0 | 5 votes |
public static void setAppBar(AppCompatActivity activity, Boolean withHomeButtonEnabled) { Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar); if (toolbar != null) { activity.setSupportActionBar(toolbar); ActionBar actionBar = activity.getSupportActionBar(); if (withHomeButtonEnabled && actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } } }
Example 16
Source File: PhotoPickerFragment.java From InstagramPhotoPicker with MIT License | 5 votes |
private void initToolBar() { if (getActivity() instanceof AppCompatActivity) { final AppCompatActivity activity = (AppCompatActivity) getActivity(); activity.setSupportActionBar(toolbar); activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); activity.getSupportActionBar().setDisplayShowTitleEnabled(false); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { activity.onBackPressed(); } }); } }
Example 17
Source File: ViewUtils.java From BlueBoard with Apache License 2.0 | 5 votes |
/** * 显示Toolbar 默认标题 */ public static void setToolbar(AppCompatActivity context, Toolbar toolbar, Boolean WithHomeButton) { context.setSupportActionBar(toolbar); if (WithHomeButton) { ActionBar actionBar = context.getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } } }
Example 18
Source File: OAppBarUtils.java From hr with GNU Affero General Public License v3.0 | 5 votes |
public static void setAppBar(AppCompatActivity activity, Boolean withHomeButtonEnabled) { Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar); if (toolbar != null) { activity.setSupportActionBar(toolbar); ActionBar actionBar = activity.getSupportActionBar(); if (withHomeButtonEnabled && actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } } }
Example 19
Source File: NewsArticleFragment.java From DoingDaily with Apache License 2.0 | 4 votes |
@Override public void setUpView(View view) { AppCompatActivity mAppCompatActivity = (AppCompatActivity) getActivity(); mAppCompatActivity.setSupportActionBar(toolbar); ActionBar actionBar = mAppCompatActivity.getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } setHasOptionsMenu(true); //处理 onOptionsItemSelected方法不被调用 bean = (NewsContentlistBean) getArguments().getSerializable(ConstantValues.KEY_BEAN); int type = getArguments().getInt(ConstantValues.KEY_VIEW_TYPE); if (bean != null) { switch (type) { case ConstantValues.VIEW_TYPE_TXT: headImage.setVisibility(View.GONE); break; case ConstantValues.VIEW_TYPE_IMAGE: GlideUtils.display(headImage,bean.getImageurls().get(0).getUrl()); headImage.setVisibility(View.VISIBLE); ViewCompat.setTransitionName(headImage, ConstantValues.SHARE_IMAGE); break; } collapsingToolbarLayout.setTitle(bean.getTitle()); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); webView.getSettings().setDomStorageEnabled(true);// 开启DOM storage API 功能 webView.getSettings().setDatabaseEnabled(true);// 开启database storage API功能 webView.getSettings().setAppCacheEnabled(true); // 开启Application Cache功能 String html = bean.getHtml().replaceFirst("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>", ""); //去除第一张IMG标签图片 webView.loadDataWithBaseURL("x-data://base", html, "text/html", "UTF-8", null); } }
Example 20
Source File: DetailFragment.java From Advanced_Android_Development with Apache License 2.0 | 4 votes |
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { ViewParent vp = getView().getParent(); if ( vp instanceof CardView ) { ((View)vp).setVisibility(View.VISIBLE); } // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); if ( Utility.usingLocalGraphics(getActivity()) ) { mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); } else { // Use weather art image Glide.with(this) .load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) .error(Utility.getArtResourceForWeatherCondition(weatherId)) .crossFade() .into(mIconView); } // Read date from cursor and update views for day of week and date long date = data.getLong(COL_WEATHER_DATE); String dateText = Utility.getFullFriendlyDayString(getActivity(),date); mDateView.setText(dateText); // Get description from weather condition ID String description = Utility.getStringForWeatherCondition(getActivity(), weatherId); mDescriptionView.setText(description); mDescriptionView.setContentDescription(getString(R.string.a11y_forecast, description)); // For accessibility, add a content description to the icon field. Because the ImageView // is independently focusable, it's better to have a description of the image. Using // null is appropriate when the image is purely decorative or when the image already // has text describing it in the same UI component. mIconView.setContentDescription(getString(R.string.a11y_forecast_icon, description)); // Read high temperature from cursor and update view boolean isMetric = Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = Utility.formatTemperature(getActivity(), high); mHighTempView.setText(highString); mHighTempView.setContentDescription(getString(R.string.a11y_high_temp, highString)); // Read low temperature from cursor and update view double low = data.getDouble(COL_WEATHER_MIN_TEMP); String lowString = Utility.formatTemperature(getActivity(), low); mLowTempView.setText(lowString); mLowTempView.setContentDescription(getString(R.string.a11y_low_temp, lowString)); // Read humidity from cursor and update view float humidity = data.getFloat(COL_WEATHER_HUMIDITY); mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity)); mHumidityView.setContentDescription(getString(R.string.a11y_humidity, mHumidityView.getText())); mHumidityLabelView.setContentDescription(mHumidityView.getContentDescription()); // Read wind speed and direction from cursor and update view float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED); float windDirStr = data.getFloat(COL_WEATHER_DEGREES); mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr)); mWindView.setContentDescription(getString(R.string.a11y_wind, mWindView.getText())); mWindLabelView.setContentDescription(mWindView.getContentDescription()); // Read pressure from cursor and update view float pressure = data.getFloat(COL_WEATHER_PRESSURE); mPressureView.setText(getString(R.string.format_pressure, pressure)); mPressureView.setContentDescription(getString(R.string.a11y_pressure, mPressureView.getText())); mPressureLabelView.setContentDescription(mPressureView.getContentDescription()); // We still need this for the share intent mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low); } AppCompatActivity activity = (AppCompatActivity)getActivity(); Toolbar toolbarView = (Toolbar) getView().findViewById(R.id.toolbar); // We need to start the enter transition after the data has loaded if ( mTransitionAnimation ) { activity.supportStartPostponedEnterTransition(); if ( null != toolbarView ) { activity.setSupportActionBar(toolbarView); activity.getSupportActionBar().setDisplayShowTitleEnabled(false); activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } else { if ( null != toolbarView ) { Menu menu = toolbarView.getMenu(); if ( null != menu ) menu.clear(); toolbarView.inflateMenu(R.menu.detailfragment); finishCreatingMenu(toolbarView.getMenu()); } } }