List of usage examples for android.widget ImageButton ImageButton
public ImageButton(Context context, AttributeSet attrs, int defStyleAttr)
From source file:com.egoclean.testpregnancy.util.ActivityHelper.java
/** * Sets up the action bar with the given title and accent color. If title is null, then * the app logo will be shown instead of a title. Otherwise, a home button and title are * visible. If color is null, then the default colorstrip is visible. *//*from ww w . jav a 2 s . co m*/ public void setupActionBar(CharSequence title, int color) { final ViewGroup actionBarCompat = getActionBarCompat(); if (actionBarCompat == null) { return; } LinearLayout.LayoutParams springLayoutParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.FILL_PARENT); springLayoutParams.weight = 1; View.OnClickListener homeClickListener = new View.OnClickListener() { public void onClick(View view) { goHome(); } }; if (title != null) { // Add Home button addActionButtonCompat(R.drawable.ic_title_home, R.string.description_home, homeClickListener, true); } else { // Add logo ImageButton logo = new ImageButton(mActivity, null, R.attr.actionbarCompatLogoStyle); logo.setOnClickListener(homeClickListener); actionBarCompat.addView(logo); } // Add title text TextView titleText = new TextView(mActivity, null, R.attr.actionbarCompatTextStyle); titleText.setLayoutParams(springLayoutParams); titleText.setText(title); actionBarCompat.addView(titleText); setActionBarColor(color); }
From source file:com.egoclean.testpregnancy.util.ActivityHelper.java
/** * Adds an action bar button to the compatibility action bar (on phones). */// w ww . j av a 2 s .c o m private View addActionButtonCompat(int iconResId, int textResId, View.OnClickListener clickListener, boolean separatorAfter) { final ViewGroup actionBar = getActionBarCompat(); if (actionBar == null) { return null; } // Create the separator ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle); separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT)); // Create the button ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle); actionButton.setLayoutParams(new ViewGroup.LayoutParams( (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height), ViewGroup.LayoutParams.FILL_PARENT)); actionButton.setImageResource(iconResId); actionButton.setScaleType(ImageView.ScaleType.CENTER); actionButton.setContentDescription(mActivity.getResources().getString(textResId)); actionButton.setOnClickListener(clickListener); // Add separator and button to the action bar in the desired order if (!separatorAfter) { actionBar.addView(separator); } actionBar.addView(actionButton); if (separatorAfter) { actionBar.addView(separator); } return actionButton; }
From source file:com.egoclean.testpregnancy.util.ActivityHelper.java
/** * Adds an action button to the compatibility action bar, using menu information from a * {@link android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state * can be changed to show a loading spinner using * {@link ActivityHelper#setRefreshActionButtonCompatState(boolean)}. *///from ww w. j a v a 2 s .co m private View addActionButtonCompatFromMenuItem(final MenuItem item) { final ViewGroup actionBar = getActionBarCompat(); if (actionBar == null) { return null; } // Create the separator ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle); separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT)); // Create the button ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle); actionButton.setId(item.getItemId()); actionButton.setLayoutParams(new ViewGroup.LayoutParams( (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height), ViewGroup.LayoutParams.FILL_PARENT)); actionButton.setImageDrawable(item.getIcon()); actionButton.setScaleType(ImageView.ScaleType.CENTER); actionButton.setContentDescription(item.getTitle()); actionButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item); } }); actionBar.addView(separator); actionBar.addView(actionButton); if (item.getItemId() == R.id.menu_refresh) { // Refresh buttons should be stateful, and allow for indeterminate progress indicators, // so add those. int buttonWidth = mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height); int buttonWidthDiv3 = buttonWidth / 3; ProgressBar indicator = new ProgressBar(mActivity, null, R.attr.actionbarCompatProgressIndicatorStyle); LinearLayout.LayoutParams indicatorLayoutParams = new LinearLayout.LayoutParams(buttonWidthDiv3, buttonWidthDiv3); indicatorLayoutParams.setMargins(buttonWidthDiv3, buttonWidthDiv3, buttonWidth - 2 * buttonWidthDiv3, 0); indicator.setLayoutParams(indicatorLayoutParams); indicator.setVisibility(View.GONE); indicator.setId(R.id.menu_refresh_progress); actionBar.addView(indicator); } return actionButton; }
From source file:com.chatwing.whitelabel.managers.ChatboxModeManager.java
@Override public boolean onCreateOptionsMenu(Menu menu) { AppCompatActivity activity = mActivityDelegate.getActivity(); final DrawerLayout drawerLayout = mActivityDelegate.getDrawerLayout(); activity.getMenuInflater().inflate(R.menu.chatbox_menu, menu); MenuItem onlineUsersItem = menu.findItem(R.id.online_users); mediaAddItem = menu.findItem(R.id.audio_add); /**/*from w w w .j a va 2 s . c o m*/ * Create badge view for online user item */ ImageButton iconView = new ImageButton(activity, null, R.style.Widget_AppCompat_ActionButton); iconView.setImageDrawable(onlineUsersItem.getIcon()); iconView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (drawerLayout.isDrawerOpen(DRAWER_GRAVITY_ONLINE_USER)) { drawerLayout.closeDrawer(DRAWER_GRAVITY_ONLINE_USER); } else { drawerLayout.openDrawer(DRAWER_GRAVITY_ONLINE_USER); } } }); // The badge view requires target view (iconView in this case) // to have a ViewGroup parent LinearLayout container = new LinearLayout(activity); container.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); container.addView(iconView); Resources res = activity.getResources(); mOnlineUsersBadgeView = new BadgeView(activity, iconView); mOnlineUsersBadgeView.setBadgePosition(BadgeView.POSITION_TOP_RIGHT); mOnlineUsersBadgeView.setTextSize(TypedValue.COMPLEX_UNIT_SP, res.getDimension(R.dimen.badge_view_text_size)); mOnlineUsersBadgeView.setBadgeMargin(res.getDimensionPixelSize(R.dimen.default_margin)); onlineUsersItem.setActionView(container); mOnlineUsersBadgeView .setBadgeBackgroundColor(mActivityDelegate.getActivity().getResources().getColor(R.color.accent)); return true; }
From source file:android.support.v7.widget.Toolbar.java
private void ensureNavButtonView() { if (mNavButtonView == null) { mNavButtonView = new ImageButton(getContext(), null, R.attr.toolbarNavigationButtonStyle); final LayoutParams lp = generateDefaultLayoutParams(); lp.gravity = GravityCompat.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); mNavButtonView.setLayoutParams(lp); }//from www . ja v a 2 s. com }
From source file:android.support.v7.widget.Toolbar.java
private void ensureCollapseButtonView() { if (mCollapseButtonView == null) { mCollapseButtonView = new ImageButton(getContext(), null, R.attr.toolbarNavigationButtonStyle); mCollapseButtonView.setImageDrawable(mCollapseIcon); mCollapseButtonView.setContentDescription(mCollapseDescription); final LayoutParams lp = generateDefaultLayoutParams(); lp.gravity = GravityCompat.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); lp.mViewType = LayoutParams.EXPANDED; mCollapseButtonView.setLayoutParams(lp); mCollapseButtonView.setOnClickListener(new OnClickListener() { @Override/*from w ww . j ava2s . c o m*/ public void onClick(View v) { collapseActionView(); } }); } }
From source file:android.support.v7ox.widget.Toolbar.java
private void ensureNavButtonView() { if (mNavButtonView == null) { mNavButtonView = new ImageButton(getContext(), null, R.attr.toolbarNavigationButtonStyle_ox); final LayoutParams lp = generateDefaultLayoutParams(); lp.gravity = GravityCompat.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); mNavButtonView.setLayoutParams(lp); }/*w w w . j a va 2 s. c om*/ }
From source file:android.support.v7ox.widget.Toolbar.java
private void ensureCollapseButtonView() { if (mCollapseButtonView == null) { mCollapseButtonView = new ImageButton(getContext(), null, R.attr.toolbarNavigationButtonStyle_ox); mCollapseButtonView.setImageDrawable(mCollapseIcon); mCollapseButtonView.setContentDescription(mCollapseDescription); final LayoutParams lp = generateDefaultLayoutParams(); lp.gravity = GravityCompat.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); lp.mViewType = LayoutParams.EXPANDED; mCollapseButtonView.setLayoutParams(lp); mCollapseButtonView.setOnClickListener(new OnClickListener() { @Override/*from w w w . ja v a 2 s . c o m*/ public void onClick(View v) { collapseActionView(); } }); } }
From source file:lewa.support.v7.widget.Toolbar.java
private void ensureNavButtonView() { if (mNavButtonView == null) { mNavButtonView = new ImageButton(getContext(), null, R.attr.toolbarNavigationButtonStyle); final LayoutParams lp = generateDefaultLayoutParams(); // lp.gravity = GravityCompat.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); lp.gravity = Gravity.CENTER_VERTICAL; mNavButtonView.setLayoutParams(lp); }// w ww . j a v a2s. co m }
From source file:lewa.support.v7.widget.Toolbar.java
private void ensureCollapseButtonView() { if (mCollapseButtonView == null) { mCollapseButtonView = new ImageButton(getContext(), null, R.attr.toolbarNavigationButtonStyle); mCollapseButtonView.setImageDrawable(mCollapseIcon); final LayoutParams lp = generateDefaultLayoutParams(); lp.gravity = GravityCompat.START | (mButtonGravity & Gravity.VERTICAL_GRAVITY_MASK); lp.mViewType = LayoutParams.EXPANDED; mCollapseButtonView.setLayoutParams(lp); mCollapseButtonView.setOnClickListener(new OnClickListener() { @Override//from w ww.j a v a 2s. co m public void onClick(View v) { collapseActionView(); } }); } }