android.support.v7.app.ActionBar Java Examples

The following examples show how to use android.support.v7.app.ActionBar. 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: MainActivity.java    From freeiot-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNavigationDrawerFragment = (NavigationDrawerFragment)
            getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
            R.id.navigation_drawer,
            (DrawerLayout) findViewById(R.id.drawer_layout));
    ActionBar actionBar = getSupportActionBar();
    actionBar.setBackgroundDrawable(getResources().getDrawable(R.color.main_red_color));

}
 
Example #2
Source File: MainActivity.java    From FlexibleSearchBar with Apache License 2.0 6 votes vote down vote up
private void initView() {
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.hide();
    }
    searchbarview = (SearchBarView) findViewById(R.id.searchbarview);
    searchbarview.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // enter search activity
            Toast.makeText(MainActivity.this, "enter search activity", Toast.LENGTH_SHORT).show();
        }
    });
    AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbarlayout);
    appBarLayout.addOnOffsetChangedListener(this);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setVerticalScrollBarEnabled(true);
    mRecyclerView.setNestedScrollingEnabled(false);
    mRecyclerView.setAdapter(new MyAdapter());
}
 
Example #3
Source File: AboutActivity.java    From Simple-Brick-Games with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activty_about);

    actionBar = getSupportActionBar();
    viewPager = (ViewPager) findViewById(R.id.pager);
    TabsPagerAdapter adapter = new TabsPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(adapter);
    actionBar.setDisplayHomeAsUpEnabled(true);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);

    ActionBar.Tab tabFirst = actionBar.newTab().setText(getString(R.string.about_tab_1)).setTabListener(this);
    ActionBar.Tab tabSecond = actionBar.newTab().setText(getString(R.string.about_tab_2)).setTabListener(this);
    ActionBar.Tab tabThird = actionBar.newTab().setText(getString(R.string.about_tab_3)).setTabListener(this);

    actionBar.addTab(tabFirst);
    actionBar.addTab(tabSecond);
    actionBar.addTab(tabThird);
    actionBar.selectTab(tabFirst);
}
 
Example #4
Source File: DrawerActivity.java    From Companion-For-PUBG-Android with MIT License 6 votes vote down vote up
@Override
protected final void onCreate(@Nullable final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setSupportActionBar(toolbar);

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    if (this.navigationView != null) {
        this.navigationView.setNavigationItemSelectedListener(this);
        this.navigationView.setCheckedItem(R.id.drawer_map);
    }
    mapSelected();
}
 
Example #5
Source File: ChatHomeActivity.java    From PlayTogether with Apache License 2.0 6 votes vote down vote up
@Override
public void afterCreate()
{
	ActionBar actionBar = getSupportActionBar();
	if (actionBar != null) actionBar.setTitle("");
	User me = AVUser.getCurrentUser(User.class);
	if (me == null)
	{
		Toast.makeText(this, "请先进行登录,", Toast.LENGTH_SHORT).show();
		finish();
	}
	//初始化用户信息
	mTvUsername.setText(me.getUsername());
	AVFile avAvatar = me.getAvatar();
	if (avAvatar != null)
		PicassoUtils.displayFitImage(this, Uri.parse(avAvatar.getThumbnailUrl(true, Constant
						.AVATAR_WIDTH, Constant.AVATAR_HEIGHT)), mIvAvatar, null);
	//初始化事件
	initEvent();
	//初始化viewpager
	initViewPagerAndTabLayout();
}
 
Example #6
Source File: WebViewActivity.java    From checkey with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    intent = getIntent();
    int resid = intent.getIntExtra(Intent.EXTRA_TITLE, 0);
    if (resid != 0)
        actionBar.setTitle(resid);

    WebView webView = (WebView) findViewById(R.id.webview);
    webView.setWebViewClient(new MyWebViewClient());
    uri = intent.getData();
    webView.loadUrl(uri.toString());
}
 
Example #7
Source File: MainActivity.java    From PinView with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar.addTab(
                actionBar.newTab()
                        .setText(mSectionsPagerAdapter.getPageTitle(i))
                        .setTabListener(this));
    }
}
 
Example #8
Source File: ActionbarextrasModule.java    From actionbarextras with MIT License 6 votes vote down vote up
/**
 * Sets the homeAsUp icon
 * @param icon
 */
private void handleSetHomeAsUpIcon(Object obj) {
	ActionBar actionBar = getActionBar();

	if (actionBar == null) {
		return;
	}

	if (obj instanceof HashMap) {
		HashMap args = (HashMap) obj;
		actionBar.setHomeAsUpIndicator(getDrawableFromFont(args));
	} else if (obj instanceof String) {
		int resId = TiUIHelper.getResourceId(resolveUrl(null, (String)obj));
		if (resId != 0) {
			actionBar.setHomeAsUpIndicator(resId);
		} else {
			Log.e(TAG, "Couldn't resolve " + (String)obj);
		}
	} else {
		Log.e(TAG, "Please pass an Object or String to handleSetHomeAsUpIcon");
	}

}
 
Example #9
Source File: MainActivity.java    From AndroidApp with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onSystemUiVisibilityChange(int visibility) {
    ActionBar ab = getSupportActionBar();
    if (ab == null)
        return;

    if ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == View.VISIBLE) {
        mToolbar.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_down));
        ab.show();
        if (fullScreenRequested)
            mFullscreenHandler.postDelayed(mSetFullScreenRunner, 5000);
    } else {
        mToolbar.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.slide_up));
        ab.hide();
    }
}
 
Example #10
Source File: BaseActivity.java    From Pigeon with MIT License 6 votes vote down vote up
/**
 * 初始化ToolBar
 *
 * @param toolbar ToolBar的实例
 * @param title 标题
 * @param isBack 是否出现返回按钮
 */
public void initToolBar(Toolbar toolbar, String title, boolean isBack) {
    toolbar.setTitle(title);
    setSupportActionBar(toolbar);
    if (isBack) {
        try {
            ActionBar actionBar = getSupportActionBar();
            if (null != actionBar)
                actionBar.setDisplayHomeAsUpEnabled(true);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }

}
 
Example #11
Source File: MapTypesAndLayerGroupsActivity.java    From android-map-sdk with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_map_types_and_layer_groups);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }

    MapFragment mapFragment = (MapFragment)getSupportFragmentManager().findFragmentById(R.id.map_fragment);
    if (mapFragment == null) {
        mapFragment = MapFragment.newInstance(new NaverMapOptions()
            .camera(new CameraPosition(NaverMap.DEFAULT_CAMERA_POSITION.target, 16, 40, 0)));
        getSupportFragmentManager().beginTransaction().add(R.id.map_fragment, mapFragment).commit();
    }
    mapFragment.getMapAsync(this);
}
 
Example #12
Source File: SettingsActivity.java    From android-dev-challenge with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    ActionBar actionBar = this.getSupportActionBar();

    // Set the action bar back button to look like an up button
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
 
Example #13
Source File: WebViewActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
private void initToolBar() {
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        //去除默认Title显示
        actionBar.setDisplayShowTitleEnabled(false);
    }
}
 
Example #14
Source File: ShortcutActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    ActionBar bar = getSupportActionBar();
    if(bar != null){
        bar.setTitle(R.string.create_shortcut);
    }
}
 
Example #15
Source File: StdGameActivity.java    From Primary with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    GridLayout answerarea = findViewById(R.id.answer_area);
    LinearLayout centercol = findViewById(R.id.centercol);
    ActionBar actionBar = getSupportActionBar();
    if (isLandscape()) {

        //answerarea.setOrientation(GridLayout.VERTICAL);
        setColumnCount(answerarea,2);

        centercol.setOrientation(LinearLayout.HORIZONTAL);

        if (actionBar != null) {
            actionBar.hide();
        }
    } else {
        //answerarea.setOrientation(GridLayout.VERTICAL);


        setColumnCount(answerarea,1);

        centercol.setOrientation(LinearLayout.VERTICAL);

        if (actionBar != null) {
            actionBar.show();
        }

    }

}
 
Example #16
Source File: ActionBarControlGridViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onUpOrCancelMotionEvent(ScrollState scrollState) {
    ActionBar ab = getSupportActionBar();
    if (scrollState == ScrollState.UP) {
        if (ab.isShowing()) {
            ab.hide();
        }
    } else if (scrollState == ScrollState.DOWN) {
        if (!ab.isShowing()) {
            ab.show();
        }
    }
}
 
Example #17
Source File: SettingsActivity.java    From GitJourney with Apache License 2.0 5 votes vote down vote up
/**
 * Set up the {@link android.app.ActionBar}, if the API is available.
 */
private void setupActionBar() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Show the Up button in the action bar.
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
 
Example #18
Source File: ConversationActivity.java    From Atomic with GNU General Public License v3.0 5 votes vote down vote up
private void hideSubtitle() {
  android.support.v7.app.ActionBar ab = getSupportActionBar();
  CharSequence t = ab.getTitle();
  ab.setDisplayShowTitleEnabled(false);
  ab.setSubtitle(null);
  ab.setDisplayShowTitleEnabled(true);
  ab.setTitle(t);
}
 
Example #19
Source File: DrawerHelper.java    From screenplay with MIT License 5 votes vote down vote up
public void bind(Activity activity, DrawerLayout layout) {

        drawerLayout = layout;
        drawerToggle = createDrawerToggle(activity);

        LayoutInflater inflater = activity.getLayoutInflater();
        
        inflater.inflate(R.layout.navigation_menu, getLayout());
        getLayout().setDrawerListener(drawerToggle);

        ActionBar actionBar = ((AppCompatActivity) activity).getSupportActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
 
Example #20
Source File: GroupActivity.java    From talk-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_group);
    BusProvider.getInstance().register(this);
    ButterKnife.inject(this);

    setSupportActionBar(mToolbar);
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(getString(R.string.my_group));

    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mAdapter.setOnItemLongClick(this);

    mSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mAdapter.filter(newText);
            return false;
        }
    });
}
 
Example #21
Source File: MainActivity.java    From GoogleVR with Apache License 2.0 5 votes vote down vote up
private void initActionBar() {
	ActionBar actionBar = getSupportActionBar();
	actionBar.setDisplayHomeAsUpEnabled(true);
	mToggle = new ActionBarDrawerToggle(this,drawerLayout, R.string.open,R.string.close);
	mToggle.syncState();
	drawerLayout.addDrawerListener(mToggle);
}
 
Example #22
Source File: FragmentTransitionSecondFragment.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void showToolbar() {
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    if (activity != null) {
        ActionBar ab = activity.getSupportActionBar();
        if (ab != null) {
            ab.show();
        }
    }
}
 
Example #23
Source File: BaseActivity.java    From Paginate with Apache License 2.0 5 votes vote down vote up
private void setupBasicUI() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);

    DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_closed);
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();
}
 
Example #24
Source File: WXPageActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
private void initUIAndData() {

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(mUri.toString().substring(mUri.toString().lastIndexOf(File.separator) + 1));

    mContainer = (ViewGroup) findViewById(R.id.container);
    mProgressBar = (ProgressBar) findViewById(R.id.progress);
    mWXHandler = new Handler(this);
    HotRefreshManager.getInstance().setHandler(mWXHandler);
    addOnListener();
  }
 
Example #25
Source File: BaseActivity.java    From ClassSchedule with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化toolbar功能为返回
 *
 * @param title
 */
protected void initBackToolbar(String title) {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        getSupportActionBar().setTitle(title);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
}
 
Example #26
Source File: PlayerControlFragment.java    From android-openslmediaplayer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onUpdateActionBarAndOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onUpdateActionBarAndOptionsMenu(menu, inflater);

    ActionBar actionBar = getActionBar();

    actionBar.setTitle(ActionBarTileBuilder.makeTitleString(
            getActivity(), R.string.title_player_control));
}
 
Example #27
Source File: RecyclerViewFragment.java    From KA27 with Apache License 2.0 5 votes vote down vote up
public void setProgressBar(ProgressBar progressBar) {
    progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000,
        ContextCompat.getColor(getActivity(), android.R.color.white)));
    ActionBar actionBar;
    if ((actionBar = getActionBar()) != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    }
}
 
Example #28
Source File: FabSortActivity.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private void configToolbar() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setTitle(R.string.fab_sort_custom_fab);
        ab.setDisplayHomeAsUpEnabled(true);
    }
    if (!isDarkTheme()) toolbar.setPopupTheme(R.style.AppTheme_PopupOverlay);
}
 
Example #29
Source File: MainActivity.java    From abelana with Apache License 2.0 5 votes vote down vote up
/**
 * Restore the ActionBar state.
 */
public void restoreActionBar() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(mTitle);
    }
}
 
Example #30
Source File: RecyclerViewNestedScrollviewFixDemoFragment.java    From android-recycler-view-wrap-content with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    ActionBar supportActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if (supportActionBar != null) {
        supportActionBar.setTitle(R.string.title_with_nestedscrollview_fix);
    }

    // Partial code from https://developer.android.com/training/material/lists-cards.html#RecyclerView

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mLayoutManager = new LinearLayoutManager(getContext());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // Disabled nested scrolling since Parent scrollview will scroll the content.
    mRecyclerView.setNestedScrollingEnabled(false);

    // specify an adapter (see also next example)
    mAdapter = new SimpleListAdapter(DataSetProvider.generateDataset());
    mRecyclerView.setAdapter(mAdapter);
}