Java Code Examples for android.support.v7.widget.Toolbar#addView()

The following examples show how to use android.support.v7.widget.Toolbar#addView() . 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: ActivityUtils.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化Toolbar,添加返回按钮,set title
 * @param toolbar
 */
public static void initBar(Toolbar toolbar, @StringRes int title) {
    toolbar.setNavigationIcon(R.drawable.ic_chevron_left_24dp);
    TextView titleView = (TextView) LayoutInflater.from(toolbar.getContext()).inflate(R.layout.text_view_new_title, null);
    titleView.setText(title);
    Toolbar.LayoutParams params = new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    toolbar.addView(titleView, params);
}
 
Example 2
Source File: BaseMessageActivity.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
private void addRightCustomViewOnActionBar(UI activity, List<SessionCustomization.OptionsButton> buttons) {
    if (CommonUtil.isEmpty(buttons)) {
        return;
    }

    Toolbar toolbar = getToolBar();
    if (toolbar == null) {
        return;
    }

    LinearLayout buttonContainer = (LinearLayout) LayoutInflater.from(activity).inflate(R.layout.nim_action_bar_custom_view, null);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
    for (final SessionCustomization.OptionsButton button : buttons) {
        ImageView imageView = new ImageView(activity);
        imageView.setImageResource(button.iconId);
        imageView.setBackgroundResource(R.drawable.nim_nim_action_bar_button_selector);
        imageView.setPadding(ScreenUtil.dip2px(10), 0, ScreenUtil.dip2px(10), 0);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                button.onClick(BaseMessageActivity.this, v, sessionId);
            }
        });
        buttonContainer.addView(imageView, params);
    }

    toolbar.addView(buttonContainer, new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.RIGHT | Gravity.CENTER));
}
 
Example 3
Source File: MainActivity.java    From ScreenShift with Apache License 2.0 5 votes vote down vote up
private void setUpToolbar() {
    showTimeout = false;
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    if(actionBar != null) {
        actionBar.setElevation(getResources().getDimension(R.dimen.toolbar_elevation));
    }
    toolbar.setTitle(R.string.app_name);
    toolbar.setTitleTextColor(Color.WHITE);
    masterSwitch = new SwitchCompat(this);
    masterSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                enableService();
            } else {
                disableService();
            }
        }
    });
    Toolbar.LayoutParams params = new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.END;
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        params.setMarginEnd((int) getResources().getDimension(R.dimen.activity_vertical_margin));
    } else {
        params.setMargins(0,0,(int) getResources().getDimension(R.dimen.activity_vertical_margin),0);
    }
    toolbar.addView(masterSwitch, params);
    boolean masterSwitchOn = PreferencesHelper.getBoolPreference(this, KEY_MASTER_SWITCH_ON);
    Log.d("masterSwitchOn", String.valueOf(masterSwitchOn));
    if(masterSwitch.isChecked() == masterSwitchOn){
        if(masterSwitchOn) enableService();
        else disableService();
    } else {
        masterSwitch.setChecked(masterSwitchOn);
    }
    showTimeout = true;
}
 
Example 4
Source File: TitleSwitcher.java    From Sky31Radio with Apache License 2.0 4 votes vote down vote up
public void setToolbar(Toolbar toolbar) {
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(300, ViewGroup.LayoutParams.WRAP_CONTENT);
    toolbar.addView(this, layoutParams);
    currentText.setText(toolbar.getTitle());
}