Java Code Examples for android.support.v7.app.ActionBar#LayoutParams

The following examples show how to use android.support.v7.app.ActionBar#LayoutParams . 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 KSYMediaPlayer_Android with Apache License 2.0 6 votes vote down vote up
public void setActionBarLayout(int layoutId, Context mContext) {
    ActionBar actionBar = getSupportActionBar();
    if (null != actionBar) {
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        LayoutInflater inflator = (LayoutInflater) this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflator.inflate(layoutId, new LinearLayout(mContext), false);
        ActionBar.LayoutParams layout = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
        actionBar.setCustomView(v, layout);
        media_net = (Button)findViewById(R.id.media_network);
        media_history = (Button)findViewById(R.id.media_history);
        media_setting = (Button)findViewById(R.id.media_setting);
        media_net.setOnClickListener(this);
        media_setting.setOnClickListener(this);
        media_history.setOnClickListener(this);
    }else{
        Toast.makeText(MainActivity.this, "ActionBar不存在", Toast.LENGTH_SHORT).show();
    }

}
 
Example 2
Source File: NetMediaActivty.java    From KSYMediaPlayer_Android with Apache License 2.0 6 votes vote down vote up
public void setActionBarLayout(int layoutId, Context mContext) {
    ActionBar actionBar = getSupportActionBar();
    if (null != actionBar) {
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        LayoutInflater inflator = (LayoutInflater) this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflator.inflate(layoutId, new LinearLayout(mContext), false);
        ActionBar.LayoutParams layout = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
        actionBar.setCustomView(v, layout);

        netHistory = (Button) findViewById(R.id.net_history);
        netScan = (Button) findViewById(R.id.net_scan);
        netSetting = (Button) findViewById(R.id.net_setting);
        netScan.setOnClickListener(this);
        netHistory.setOnClickListener(this);
        netSetting.setOnClickListener(this);

    }else{
        Toast.makeText(NetMediaActivty.this, "ActionBar不存在", Toast.LENGTH_SHORT).show();
    }

}
 
Example 3
Source File: BaseActivity.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void setToolbar(View view, ActionBar.LayoutParams params, boolean enableBack) {
    if (getSupportActionBar() == null) {
        throw new RuntimeException("Action bar is not set!");
    }
    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setDisplayUseLogoEnabled(false);
    getSupportActionBar().setCustomView(view, params);
    if (enableBack) {
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    } else {
        getSupportActionBar().setDisplayShowHomeEnabled(false);
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        Toolbar parent = (Toolbar) view.getParent();
        parent.setContentInsetsAbsolute(0, 0);
    }
}
 
Example 4
Source File: ActionBarDisplayOptions.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.action_bar_display_options);

    findViewById(R.id.toggle_home_as_up).setOnClickListener(this);
    findViewById(R.id.toggle_show_home).setOnClickListener(this);
    findViewById(R.id.toggle_use_logo).setOnClickListener(this);
    findViewById(R.id.toggle_show_title).setOnClickListener(this);
    findViewById(R.id.toggle_show_custom).setOnClickListener(this);
    findViewById(R.id.toggle_navigation).setOnClickListener(this);
    findViewById(R.id.cycle_custom_gravity).setOnClickListener(this);
    findViewById(R.id.toggle_visibility).setOnClickListener(this);

    // Configure several action bar elements that will be toggled by display options.
    mCustomView = getLayoutInflater().inflate(R.layout.action_bar_display_options_custom, null);
    mCustomViewLayoutParams = new ActionBar.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    final ActionBar bar = getSupportActionBar();
    bar.setCustomView(mCustomView, mCustomViewLayoutParams);
    bar.addTab(bar.newTab().setText("Tab 1").setTabListener(this));
    bar.addTab(bar.newTab().setText("Tab 2").setTabListener(this));
    bar.addTab(bar.newTab().setText("Tab 3").setTabListener(this));
}
 
Example 5
Source File: BaseActivity.java    From SimpleAdapterDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);
    }
 
Example 6
Source File: BaseActivity.java    From CameraMaskDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);
    }
 
Example 7
Source File: BaseActivity.java    From WheelViewDemo with Apache License 2.0 5 votes vote down vote up
@Override
    protected void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);
    }
 
Example 8
Source File: HomeScreenActivity.java    From Gazetti_Newspaper_Reader with MIT License 5 votes vote down vote up
private void setupCustomActionBar() {
    View actionBarCustomView = LayoutInflater.from(this).inflate(R.layout.homescreen_actionbar, null);
    ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
            ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);

    getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getSupportActionBar().setCustomView(actionBarCustomView, params);
    TextView heading = (TextView) actionBarCustomView.findViewById(R.id.homescreen_action_bar_title);
    ImageView gazettiLogo = (ImageView) actionBarCustomView.findViewById(R.id.gazetti_logo);

    heading.setAnimation(getEntryAnimation(ENTRY_ANIMATION_TITLE));
    gazettiLogo.setAnimation(getEntryAnimation(ENTRY_ANIMATION_LOGO));
}
 
Example 9
Source File: MyToolBar.java    From Mobike with Apache License 2.0 5 votes vote down vote up
private void initview() {
        if (mView == null) {
            mInflater = LayoutInflater.from(getContext());
            mView = mInflater.inflate(R.layout.toolbar, null);
            mLRippleView = (RippleView) mView.findViewById(R.id.more);
            mRRippleView = (RippleView) mView.findViewById(R.id.more1);
            toolbar_rightButton = (ImageView) mView.findViewById(R.id.id_btn_right);
            toolbar_title = (TextView) mView.findViewById(R.id.id_tv_title);
            toolbar_searchview = (EditText) mView.findViewById(R.id.id_et_search);
            toolbar_leftButton = (ImageView) mView.findViewById(R.id.id_ib_navigation);
            ActionBar.LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            addView(mView, lp);
//            if (showSearchView) {
//                showSearchview();
//                hideTitle();
//            } else {
//                hideSearchview();
//                showTitle();
//                if (title != null) {
//                    toolbar_title.setText(title);
//                }
//            }
//            Log.d("left_button_icon", "initview:5"+left_button_icon);
//            if (left_button_icon != null) {
//
//                toolbar_leftButton.setBackground(left_button_icon);
//                toolbar_leftButton.setVisibility(VISIBLE);
//            }
//
//            if (right_button_icon != null) {
//                toolbar_rightButton.setImageDrawable(right_button_icon);
//                toolbar_rightButton.setVisibility(VISIBLE);
//            }

        }

    }
 
Example 10
Source File: DetailsActivity.java    From ExpressHelper with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void setUpViews() {
	mContentLayout = (LinearLayout) findViewById(R.id.content_list);
	tv_company = (TextView) findViewById(R.id.tv_express_company);
	tv_mail_no = (TextView) findViewById(R.id.tv_mail_no);
	tv_status = (TextView) findViewById(R.id.tv_status);
	tv_round_center = (TextView) findViewById(R.id.center_text);
	iv_round = (CircleImageView) findViewById(R.id.iv_round);
	mButtonNumberVisible = (ImageButton) findViewById(R.id.btn_number_visible);

	try {
		ViewCompat.setElevation(findViewById(R.id.headerView), getResources().getDimension(R.dimen.toolbar_elevation));
	} catch (NullPointerException e) {
		// Just ignore it.
	}

	mEditTextName = new EditText(mActionBar.getThemedContext());
	ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL);
	mActionBar.setCustomView(mEditTextName, lp);
	mActionBar.setDisplayShowCustomEnabled(false);
	mActionBar.setDisplayShowTitleEnabled(true);
	mButtonNumberVisible.setOnClickListener(new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			toggleNumberShowing();
		}
	});
}
 
Example 11
Source File: MapzenSearchViewActivity.java    From android with Apache License 2.0 5 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_search);

  listView = (AutoCompleteListView) findViewById(R.id.list_view);
  autocompleteAdapter = new AutoCompleteAdapter(this, android.R.layout.simple_list_item_1);
  listView.setAdapter(autocompleteAdapter);

  peliasLocationProvider = new MapzenMapPeliasLocationProvider(this);

  MapView mapView = (MapView) findViewById(R.id.map_view);
  mapView.getMapAsync(new OnMapReadyCallback() {
    @Override public void onMapReady(MapzenMap mapzenMap) {
      MapzenSearchViewActivity.this.mapzenMap = mapzenMap;
      mapzenMap.setPersistMapData(true);
      configMap();
    }
  });

  mapzenSearch = new MapzenSearch(this);
  mapzenSearch.setLocationProvider(peliasLocationProvider);

  PeliasSearchView peliasSearchView = new PeliasSearchView(this);
  ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
      ActionBar.LayoutParams.MATCH_PARENT);
  getSupportActionBar().setCustomView(peliasSearchView, lp);
  getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
  setupPeliasSearchView(peliasSearchView);
}
 
Example 12
Source File: TaskManager.java    From Kernel-Tuner with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Foreground Application = 10040
 * Secondary Server  	  = 10041
 * Content Providers      = 10043
 * Empty Application      = 10079
 * Visible Application    = 10025
 * Hidden Application     =
 * */
/*
 private static final int BACKGROUND = RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
 private static final int EMPTY = RunningAppProcessInfo.IMPORTANCE_EMPTY;
 private static final int FOREGROUND = RunningAppProcessInfo.IMPORTANCE_FOREGROUND;
 private static final int PERCEPTIBLE = RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE;
 private static final int SERVICE = RunningAppProcessInfo.IMPORTANCE_SERVICE;
 private static final int VISIBLE = RunningAppProcessInfo.IMPORTANCE_VISIBLE;
 */

@Override
public void onCreate(Bundle savedInstanceState)
{
       handler = new Handler();
	preferences = PreferenceManager.getDefaultSharedPreferences(this);

	super.onCreate(savedInstanceState);

	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	setContentView(R.layout.activity_tm_list);

	pbLoading = (ProgressBar)findViewById(R.id.pbLoading);
	
	getSupportActionBar().setTitle(getResources().getString(R.string.title_task_manager));
	getSupportActionBar().setSubtitle(null);
	getSupportActionBar().setIcon(R.drawable.tm);

	ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
	View customNav = LayoutInflater.from(this).inflate(R.layout.ram_layout, null);

	((TextView)customNav.findViewById(R.id.free)).setText(Html.fromHtml("<b>" + getResources().getString(R.string.mem_free) + "</b>" + getFreeRAM() + "MB"));
	((TextView)customNav.findViewById(R.id.total)).setText(Html.fromHtml("<b>" + getResources().getString(R.string.mem_total) + "</b>" + getTotalRAM() + "MB"));

       //Attach to the action bar
       getSupportActionBar().setCustomView(customNav, lp);
       getSupportActionBar().setDisplayShowCustomEnabled(true);

	tmListView =  (ListView)findViewById(R.id.list);
	pm = getPackageManager();
	
	tmAdapter = new TMAdapter(this, R.layout.tm_row);
       tmListView.setAdapter(tmAdapter);
	tmListView.setOnItemClickListener(this);

	loading = (ProgressBar)findViewById(R.id.loading);
	system = (CheckBox)findViewById(R.id.system);
	user = (CheckBox)findViewById(R.id.user);
	other = (CheckBox)findViewById(R.id.other);

	system.setChecked(preferences.getBoolean("tm_system", false));
	user.setChecked(preferences.getBoolean("tm_user", true));
	other.setChecked(preferences.getBoolean("tm_other", false));

	system.setOnCheckedChangeListener(new Listener());
	user.setOnCheckedChangeListener(new Listener());
	other.setOnCheckedChangeListener(new Listener());

       new GetRunningApps(true).execute();
}
 
Example 13
Source File: CPUActivity.java    From Kernel-Tuner with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
    uiHandler = new Handler();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cpu);

    showAllCores = PrefsManager.cpuShowAllCores();
    ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    View view = getLayoutInflater().inflate(R.layout.layout_cpu_ab_switch, null);
    mSwitch = (Switch) view.findViewById(R.id.swShowAllCores);
    mSwitch.setChecked(showAllCores);
    mSwitch.setOnCheckedChangeListener(this);
    mSwitch.setOnTouchListener(this);

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setCustomView(view, lp);

    pbLoading = (ProgressBar) findViewById(R.id.pbLoading);
    mList = (ListView) findViewById(R.id.list);
    mList.setOnItemClickListener(this);
    mListAdapter = new CPUAdapter(this, new ArrayList<CPU>());
    mList.setAdapter(mListAdapter);
    refreshView();

    if (Constants.MPDECISION.exists()/* || new File(Constants.MPDECISION_BINARY).exists()*/)
    {
        Button mp = (Button) findViewById(R.id.btn_mpdecision);
        mp.setOnClickListener(new SimpleStartActivityListener(Mpdecision.class));
        mp.setOnLongClickListener(new InfoListener(R.drawable.main_mp,
                getResources().getString(R.string.info_mpd_title),
                getResources().getString(R.string.info_mpd_text),
                Constants.G_S_URL_PREFIX + "mp-decision", true));
        mp.setVisibility(View.VISIBLE);
    }
    if (Constants.THERMALD.exists()/* || new File(Constants.THERMALD_BINARY).exists()*/)
    {
        Button thermal = (Button) findViewById(R.id.btn_thermal);
        thermal.setOnClickListener(new SimpleStartActivityListener(Thermald.class));

        thermal.setOnLongClickListener(new InfoListener(R.drawable.main_thermal,
                getResources().getString(R.string.info_thermal_title),
                getResources().getString(R.string.info_thermal_text), "", false));
        thermal.setVisibility(View.VISIBLE);
    }

}
 
Example 14
Source File: ActionBarDisplayOptions.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
@Override
public void onClick(View v) {
    final ActionBar bar = getSupportActionBar();
    int flags = 0;
    switch (v.getId()) {
        case R.id.toggle_home_as_up:
            flags = ActionBar.DISPLAY_HOME_AS_UP;
            break;
        case R.id.toggle_show_home:
            flags = ActionBar.DISPLAY_SHOW_HOME;
            break;
        case R.id.toggle_use_logo:
            flags = ActionBar.DISPLAY_USE_LOGO;
            break;
        case R.id.toggle_show_title:
            flags = ActionBar.DISPLAY_SHOW_TITLE;
            break;
        case R.id.toggle_show_custom:
            flags = ActionBar.DISPLAY_SHOW_CUSTOM;
            break;
        case R.id.toggle_navigation:
            bar.setNavigationMode(
                    bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD
                            ? ActionBar.NAVIGATION_MODE_TABS
                            : ActionBar.NAVIGATION_MODE_STANDARD);
            return;
        case R.id.cycle_custom_gravity: {
            ActionBar.LayoutParams lp = mCustomViewLayoutParams;
            int newGravity = 0;
            switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                case Gravity.LEFT:
                    newGravity = Gravity.CENTER_HORIZONTAL;
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    newGravity = Gravity.RIGHT;
                    break;
                case Gravity.RIGHT:
                    newGravity = Gravity.LEFT;
                    break;
            }
            lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity;
            bar.setCustomView(mCustomView, lp);
            return;
        }
        case R.id.toggle_visibility:
            if (bar.isShowing()) {
                bar.hide();
            } else {
                bar.show();
            }
            return;
    }

    int change = bar.getDisplayOptions() ^ flags;
    bar.setDisplayOptions(change, flags);
}
 
Example 15
Source File: BaseActivity.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
protected void setToolbar(View view, ActionBar.LayoutParams params) {
    setToolbar(view, params, true);
}
 
Example 16
Source File: EmptyFragmentActivity.java    From WheelViewDemo with Apache License 2.0 4 votes vote down vote up
@Override
    public void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        //You can initialize custom action bar here.
        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        TextView tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        tvTitle.setText(getClass().getSimpleName().replace("Activity", ""));
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ImageView ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        ActionMenuView actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);

        String title = getIntent().getStringExtra(EXTRA_TITLE);
        tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title);
    }
 
Example 17
Source File: EmptyFragmentActivity.java    From CameraMaskDemo with Apache License 2.0 4 votes vote down vote up
@Override
    public void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        //You can initialize custom action bar here.
        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        TextView tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        tvTitle.setText(getClass().getSimpleName().replace("Activity", ""));
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ImageView ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        ActionMenuView actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);

        String title = getIntent().getStringExtra(EXTRA_TITLE);
        tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title);
    }
 
Example 18
Source File: EmptyFragmentActivity.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
@Override
    public void initActionBar(ActionBar actionBar) {
        if (actionBar == null)
            return;

        //You can initialize custom action bar here.
        int padding = CompatResourceUtils.getDimensionPixelSize(this, R.dimen.space_12);
        FrameLayout customView = new FrameLayout(this);
//        customView.setPadding(padding, 0, padding, 0);
        ActionBar.LayoutParams barParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, WindowUtils.getActionBarSize(this));
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(customView, barParams);
        //添加标题
        TextView tvTitle = new TextView(this);
        tvTitle.setTextColor(Color.WHITE);
        tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
        tvTitle.setGravity(Gravity.CENTER);
        tvTitle.setText(getClass().getSimpleName().replace("Activity", ""));
        customView.addView(tvTitle, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        //添加返回按钮
        ImageView ivBack = new ImageView(this);
        ivBack.setPadding(padding / 2, 0, padding / 2, 0);
        ivBack.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        ivBack.setImageResource(R.drawable.ic_chevron_left_white_24dp);
        ivBack.setBackground(WindowUtils.getSelectableItemBackgroundBorderless(this));
        customView.addView(ivBack, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //添加menu菜单
        ActionMenuView actionMenuView = new ActionMenuView(this);
        FrameLayout.LayoutParams menuParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        menuParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
        customView.addView(actionMenuView, menuParams);

        String title = getIntent().getStringExtra(EXTRA_TITLE);
        tvTitle.setText(TextUtils.isEmpty(title) ? getClass().getSimpleName().replace("Activity", "") : title);
    }