Java Code Examples for android.support.v7.widget.Toolbar#LayoutParams
The following examples show how to use
android.support.v7.widget.Toolbar#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: ToolbarWidget.java From relight with Apache License 2.0 | 6 votes |
@Override public void updateProps(Toolbar view) { super.updateProps(view); for (Widget widget : children) { while (widget instanceof ContainerWidget) { widget = ((ContainerWidget) widget).getInnerWidget(); } if (widget instanceof BaseAndroidWidget) { View v = widget.render(); ViewGroup.LayoutParams layoutParams = v.getLayoutParams(); if (layoutParams instanceof Toolbar.LayoutParams) { Integer layoutGravity = ((BaseAndroidWidget) widget).layoutGravity; if (layoutGravity != null) ViewUtils.setLayoutGravity((Toolbar.LayoutParams) layoutParams, v, layoutGravity); } } } }
Example 2
Source File: ToolbarEx.java From SimpleProject with MIT License | 5 votes |
/** * 设置右边Icon的资源 * @param resId * @param horizontalPadding * @param marginRight 最右边Icon的右边距 * @param listeners * @return */ public ToolbarEx setRightIcon(@DrawableRes int resId, int horizontalPadding, int marginRight, OnClickListener listeners) { Toolbar.LayoutParams params = generateDefaultLayoutParams(); params.rightMargin = marginRight; params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; rightIcon = new ImageView(getContext()); rightIcon.setImageResource(resId); rightIcon.setPadding(horizontalPadding, 0, horizontalPadding, 0); rightIcon.setOnClickListener(listeners); addView(rightIcon, params); return this; }
Example 3
Source File: ToolbarEx.java From SimpleProject with MIT License | 5 votes |
/** * 设置右边多个Icon资源 * @param resIds * @param horizontalPadding 每个Icon的padding * @param marginRight 最右边icon的右边距 * @param listeners * @return */ public ToolbarEx setRightIcons(@DrawableRes int[] resIds, int horizontalPadding, int marginRight, OnClickListener[] listeners) { if (resIds == null || resIds.length == 0) { throw new IllegalArgumentException("resIds can't be null"); } if (listeners == null || listeners.length == 0) { throw new IllegalArgumentException("listeners can't be null"); } if (resIds.length != listeners.length) { throw new IllegalArgumentException("resIds's length should equals listeners's length"); } Toolbar.LayoutParams params = generateDefaultLayoutParams(); params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; LinearLayout rightIconLayout = new LinearLayout(getContext()); rightIconLayout.setPadding(0, 0, marginRight, 0); rightIconLayout.setOrientation(LinearLayout.HORIZONTAL); rightIcons = new ImageView[resIds.length]; LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT); for (int i = 0; i < resIds.length; i++) { rightIcons[i] = new ImageView(getContext()); rightIcons[i].setPadding(horizontalPadding, 0, horizontalPadding, 0); rightIcons[i].setImageResource(resIds[i]); rightIcons[i].setOnClickListener(listeners[i]); rightIconLayout.addView(rightIcons[i], iconParams); } addView(rightIconLayout, params); return this; }
Example 4
Source File: IssuersActivity.java From px-android with MIT License | 5 votes |
private void initializeLowResControls() { mLowResToolbar = findViewById(R.id.mpsdkRegularToolbar); mLowResTitleToolbar = findViewById(R.id.mpsdkTitle); if (CheckoutTimer.getInstance().isTimerEnabled()) { final Toolbar.LayoutParams marginParams = new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); marginParams.setMargins(0, 0, 0, 0); mLowResTitleToolbar.setLayoutParams(marginParams); mLowResTitleToolbar.setTextSize(17); mTimerTextView.setTextSize(15); } mLowResToolbar.setVisibility(View.VISIBLE); }
Example 5
Source File: InstallmentsActivity.java From px-android with MIT License | 5 votes |
private void initializeLowResControls() { lowResToolbar = findViewById(R.id.mpsdkRegularToolbar); lowResTitleToolbar = findViewById(R.id.mpsdkTitle); if (CheckoutTimer.getInstance().isTimerEnabled()) { final Toolbar.LayoutParams marginParams = new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); marginParams.setMargins(0, 0, 0, 6); lowResTitleToolbar.setLayoutParams(marginParams); lowResTitleToolbar.setTextSize(TOOLBAR_TEXT_SIZE); timerTextView.setTextSize(TIMER_TEXT_SIZE); } lowResToolbar.setVisibility(View.VISIBLE); }
Example 6
Source File: ActivityUtils.java From HaiNaBaiChuan with Apache License 2.0 | 5 votes |
/** * 初始化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 7
Source File: PhotoCropActivity.java From Yahala-Messenger with MIT License | 5 votes |
private Toolbar createToolbar() { Toolbar toolbar = new Toolbar(parentActivity); Toolbar.LayoutParams toolBarParams = new Toolbar.LayoutParams( Toolbar.LayoutParams.MATCH_PARENT, R.attr.actionBarSize ); toolbar.setLayoutParams(toolBarParams); toolbar.setVisibility(View.VISIBLE); return toolbar; }
Example 8
Source File: MainActivity.java From ScreenShift with Apache License 2.0 | 5 votes |
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 9
Source File: ViewUtils.java From relight with Apache License 2.0 | 4 votes |
public static void setLayoutGravity(Toolbar.LayoutParams lp, View view, int layoutGravity) { lp.gravity = layoutGravity; view.requestLayout(); }
Example 10
Source File: ToolbarEx.java From SimpleProject with MIT License | 4 votes |
@Override protected LayoutParams generateDefaultLayoutParams() { return new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, toolbarHeight); }
Example 11
Source File: CanToolBar.java From CanPhotos with Apache License 2.0 | 4 votes |
private void init() { int dp_15 = (int) getResources().getDimension(R.dimen.dimen_15); tv_left = new TextView(getContext()); Toolbar.LayoutParams paramsLeft = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.MATCH_PARENT); paramsLeft.gravity = Gravity.LEFT; tv_left.setLayoutParams(paramsLeft); tv_left.setTextColor(Color.WHITE); tv_left.setGravity(Gravity.CENTER); tv_left.setTextSize(15); tv_left.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.button_back, 0, 0, 0); tv_left.setPadding(dp_15, 0, dp_15, 0); tv_left.setSingleLine(); addView(tv_left); tv_center = new TextView(getContext()); Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER; tv_center.setLayoutParams(params); tv_center.setTextColor(Color.WHITE); tv_center.setTextSize(20); tv_center.setGravity(Gravity.CENTER); tv_center.setSingleLine(); tv_center.setEllipsize(TextUtils.TruncateAt.END); addView(tv_center); tv_right = new TextView(getContext()); Toolbar.LayoutParams paramsRight = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.MATCH_PARENT); paramsRight.gravity = Gravity.RIGHT; tv_right.setLayoutParams(paramsRight); tv_right.setTextColor(Color.WHITE); tv_right.setGravity(Gravity.CENTER); tv_right.setTextSize(15); tv_right.setPadding(dp_15, 0, dp_15, 0); tv_right.setSingleLine(); addView(tv_right); }