Java Code Examples for android.widget.ImageButton#setBackgroundDrawable()

The following examples show how to use android.widget.ImageButton#setBackgroundDrawable() . 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: ImageViewButtonItem.java    From RichEditorView with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@NonNull
@Override
public ImageButton createView() {
    ImageButton imageViewButton = new ImageButton(getContext());
    if (!enableAutoSet) {
        //无边框的带有水波纹的按钮样式
        TypedArray typedArray = getContext().obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackgroundBorderless});
        Drawable drawable = typedArray.getDrawable(0);
        imageViewButton.setBackgroundDrawable(drawable);
        typedArray.recycle();
    } else {
        imageViewButton.setBackgroundDrawable(null);
    }

    imageViewButton.setImageResource(idRes);
    imageViewButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    return imageViewButton;
}
 
Example 2
Source File: SpringFloatingActionMenu.java    From SpringFloatingActionMenu with Apache License 2.0 6 votes vote down vote up
private ArrayList<ImageButton> generateFollowCircles() {

        int diameter = mFAB.getType() == FloatingActionButton.TYPE_NORMAL ?
                Utils.getDimension(mContext, R.dimen.fab_size_normal) :
                Utils.getDimension(mContext, R.dimen.fab_size_mini);

        ArrayList<ImageButton> circles = new ArrayList<>(mMenuItems.size());
        for (MenuItem item : mMenuItems) {
            ImageButton circle = new ImageButton(mContext);
            OvalShape ovalShape = new OvalShape();
            ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
            shapeDrawable.getPaint().setColor(getResources().getColor(item.getBgColor()));
            circle.setBackgroundDrawable(shapeDrawable);
            circle.setImageResource(item.getIcon());
            LayoutParams lp = new LayoutParams(diameter, diameter);
            circle.setLayoutParams(lp);
            circles.add(circle);
        }

        return circles;
    }
 
Example 3
Source File: FeedDetailActivity.java    From umeng_community_android with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void initTitleLayout() {
    TextView titleTextView = (TextView) findViewById(ResFinder.getId(
            "umeng_comm_title_tv"));
    titleTextView.setText(ResFinder.getString("umeng_comm_feed_detail"));
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);

    // back btn
    findViewById(ResFinder.getId("umeng_comm_title_back_btn")).setOnClickListener(this);
    // 刷新按钮
    mRefreshButton = (ImageButton) findViewById(ResFinder.getId(
            "umeng_comm_title_setting_btn"));
    LayoutParams layoutParams = (LayoutParams) mRefreshButton.getLayoutParams();
    layoutParams.width = DeviceUtils.dp2px(this, 20);
    layoutParams.height = DeviceUtils.dp2px(this, 20);
    layoutParams.rightMargin = DeviceUtils.dp2px(getApplicationContext(), 4);
    mRefreshButton.setLayoutParams(layoutParams);
    mRefreshButton.setBackgroundDrawable(ResFinder.getDrawable("umeng_comm_more"));
    mRefreshButton.setOnClickListener(new LoginOnViewClickListener() {
        @Override
        protected void doAfterLogin(View v) {
            mActionDialog.show();
        }
    });
}
 
Example 4
Source File: QuestionWidget.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void addHelpPlaceholder() {
    if (!mPrompt.hasHelp()) {
        return;
    }

    helpPlaceholder = new FrameLayout(this.getContext());
    helpPlaceholder.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT));

    final ImageButton trigger = new ImageButton(getContext());
    trigger.setScaleType(ScaleType.FIT_CENTER);
    trigger.setImageResource(R.drawable.icon_info_outline_lightcool);
    trigger.setBackgroundDrawable(null);
    trigger.setOnClickListener(v -> {
        trigger.setImageResource(R.drawable.icon_info_fill_lightcool);
        fireHelpText(() -> {
            // back to the old icon
            trigger.setImageResource(R.drawable.icon_info_outline_lightcool);
        });
    });
    trigger.setId(847294011);
    LinearLayout triggerLayout = new LinearLayout(getContext());
    triggerLayout.setOrientation(LinearLayout.HORIZONTAL);
    triggerLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    triggerLayout.setGravity(Gravity.RIGHT);
    triggerLayout.addView(trigger);

    MediaLayout helpLayout = createHelpLayout();
    helpLayout.setBackgroundResource(R.color.very_light_blue);
    helpPlaceholder.addView(helpLayout);

    this.addView(triggerLayout);
    this.addView(helpPlaceholder);
    helpPlaceholder.setVisibility(View.GONE);
}
 
Example 5
Source File: FloatingToolbar.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private ImageButton createOverflowButton() {
    final ImageButton overflowButton = new ImageButton(mContext);
    overflowButton.setLayoutParams(new ViewGroup.LayoutParams(AndroidUtilities.dp(56), AndroidUtilities.dp(48)));
    overflowButton.setPaddingRelative(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12));
    overflowButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    overflowButton.setImageDrawable(mOverflow);
    int color;
    if (currentStyle == STYLE_DIALOG) {
        color = Theme.getColor(Theme.key_dialogTextBlack);
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
    } else if (currentStyle == STYLE_BLACK) {
        color = 0xfffafafa;
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x40ffffff, 1));
    } else {
        color = Theme.getColor(Theme.key_windowBackgroundWhiteBlackText);
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
    }
    mOverflow.setTint(color);
    mArrow.setTint(color);
    mToArrow.setTint(color);
    mToOverflow.setTint(color);
    overflowButton.setOnClickListener(v -> {
        if (mIsOverflowOpen) {
            overflowButton.setImageDrawable(mToOverflow);
            mToOverflow.start();
            closeOverflow();
        } else {
            overflowButton.setImageDrawable(mToArrow);
            mToArrow.start();
            openOverflow();
        }
    });
    return overflowButton;
}
 
Example 6
Source File: FloatingToolbar.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private ImageButton createOverflowButton() {
    final ImageButton overflowButton = new ImageButton(mContext);
    overflowButton.setLayoutParams(new ViewGroup.LayoutParams(AndroidUtilities.dp(56), AndroidUtilities.dp(48)));
    overflowButton.setPaddingRelative(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16), AndroidUtilities.dp(12));
    overflowButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    overflowButton.setImageDrawable(mOverflow);
    int color;
    if (currentStyle == STYLE_DIALOG) {
        color = Theme.getColor(Theme.key_dialogTextBlack);
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
    } else if (currentStyle == STYLE_BLACK) {
        color = 0xfffafafa;
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(0x40ffffff, 1));
    } else {
        color = Theme.getColor(Theme.key_windowBackgroundWhiteBlackText);
        overflowButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector), 1));
    }
    mOverflow.setTint(color);
    mArrow.setTint(color);
    mToArrow.setTint(color);
    mToOverflow.setTint(color);
    overflowButton.setOnClickListener(v -> {
        if (mIsOverflowOpen) {
            overflowButton.setImageDrawable(mToOverflow);
            mToOverflow.start();
            closeOverflow();
        } else {
            overflowButton.setImageDrawable(mToArrow);
            mToArrow.start();
            openOverflow();
        }
    });
    return overflowButton;
}
 
Example 7
Source File: MenuItemView.java    From SpringFloatingActionMenu with Apache License 2.0 4 votes vote down vote up
private void init(Context context) {

        Resources resources = getResources();
        int diameterPX = Utils.dpToPx(mMenuItem.getDiameter(), resources);
        this.mDiameter = diameterPX;
        mBtn = new ImageButton(context);
        LayoutParams btnLp = new LayoutParams(diameterPX, diameterPX);
        btnLp.gravity = Gravity.CENTER_HORIZONTAL;
        btnLp.bottomMargin = Util.dpToPx(mGapSize, resources);
        mBtn.setLayoutParams(btnLp);
        OvalShape ovalShape = new OvalShape();
        ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
        shapeDrawable.getPaint().setColor(resources.getColor(mMenuItem.getBgColor()));
        mBtn.setBackgroundDrawable(shapeDrawable);
        mBtn.setImageResource(mMenuItem.getIcon());
        mBtn.setClickable(false);
        addView(mBtn);

        mLabel = new TextView(context);
        LayoutParams labelLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        labelLp.gravity = Gravity.CENTER_HORIZONTAL;
        mLabel.setLayoutParams(labelLp);
        mLabel.setText(mMenuItem.getLabel());
        mLabel.setTextColor(resources.getColor(mMenuItem.getTextColor()));
        mLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize);
        addView(mLabel);

        setOrientation(LinearLayout.VERTICAL);
        if(mAlphaAnimation) {
            setAlpha(0);
        }

        getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
                applyPressAnimation();
                ViewGroup parent = (ViewGroup) getParent();
                parent.setClipChildren(false);
                parent.setClipToPadding(false);
                setClipChildren(false);
                setClipToPadding(false);
            }
        });


    }
 
Example 8
Source File: Skeleton.java    From YiBo with Apache License 2.0 4 votes vote down vote up
private void initLayout() {
	LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       inflater.inflate(R.layout.home_page, this, true);
       ThemeUtil.setRootBackground(this);
       propertySupport = new PropertyChangeSupport(this);

       ibProfileImage = (ImageButton) this.findViewById(R.id.ibProfileImage);
       TextView tvTitle = (TextView) this.findViewById(R.id.tvTitle);
       ImageButton ibGroup = (ImageButton) this.findViewById(R.id.ibGroup);
       ImageButton ibEdit = (ImageButton) this.findViewById(R.id.ibEdit);
       
       Button btnMention = (Button) this.findViewById(R.id.btnMention);
       Button btnComment = (Button) this.findViewById(R.id.btnComment);
       Button btnDirectMessage = (Button) this.findViewById(R.id.btnDirectMessage);

       llFooter = (LinearLayout) this.findViewById(R.id.llFooter);
	btnMyHome = (Button) this.findViewById(R.id.btnMyHome);
	btnMessage = (Button) this.findViewById(R.id.btnMessage);
	btnProfile = (Button) this.findViewById(R.id.btnProfile);
	btnApp = (Button) this.findViewById(R.id.btnApp);
	btnMore = (Button) this.findViewById(R.id.btnMore);
	
	//主题
	Theme theme = ThemeUtil.createTheme(getContext());
	LinearLayout llHeader = (LinearLayout)this.findViewById(R.id.llHeader);
	llHeader.setBackgroundDrawable(theme.getDrawable("bg_header"));
	llHeader.setGravity(Gravity.CENTER_VERTICAL);
	ibProfileImage.setBackgroundDrawable(theme.getDrawable("bg_account_display"));
	ibGroup.setImageDrawable(theme.getDrawable("selector_btn_group"));
	Drawable bgHeaderDivider = theme.getDrawable("bg_header_divider");
	ibGroup.setBackgroundDrawable(bgHeaderDivider);
	ibEdit.setBackgroundDrawable(theme.getDrawable("selector_btn_status"));
	ibEdit.setImageDrawable(bgHeaderDivider);
	tvTitle.setTextColor(theme.getColorStateList("selector_header_title"));
	
	btnMention.setBackgroundDrawable(theme.getDrawable("selector_tab_mention"));
	btnMention.setTextColor(theme.getColorStateList("selector_header_title"));
	btnComment.setBackgroundDrawable(theme.getDrawable("selector_tab_comment"));
	btnComment.setTextColor(theme.getColorStateList("selector_header_title"));
	btnDirectMessage.setBackgroundDrawable(theme.getDrawable("selector_tab_direct_message"));
	btnDirectMessage.setTextColor(theme.getColorStateList("selector_header_title"));
	
       myHomeDrawable = theme.getDrawable("selector_tab_home");
       myHomeRefreshDrawable = theme.getDrawable("selector_tab_home_refresh");
       messageDrawable = theme.getDrawable("selector_tab_message");
       messageRefreshDrawable = theme.getDrawable("selector_tab_message_refresh");
       profileDrawable = theme.getDrawable("selector_tab_profile");
       profileRefreshDrawable = theme.getDrawable("selector_tab_profile_refresh");

       llFooter.setBackgroundDrawable(theme.getDrawable("bg_footer"));
       llFooter.setPadding(0, 0, 0, 0);
	btnMyHome.setBackgroundDrawable(myHomeDrawable);
	btnMessage.setBackgroundDrawable(messageDrawable);
	btnProfile.setBackgroundDrawable(profileDrawable);
	btnApp.setBackgroundDrawable(theme.getDrawable("selector_tab_app"));
	btnMore.setBackgroundDrawable(theme.getDrawable("selector_tab_more"));
}