Java Code Examples for android.view.View#setBackgroundResource()

The following examples show how to use android.view.View#setBackgroundResource() . 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: AppMsg.java    From v2ex-daily-android with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @author mengguoqiang 扩展支持设置字体大小
 * Make a {@link com.yugy.v2ex.daily.widget.AppMsg} with a custom view. It can be used to create non-floating notifications if floating is false.
 *
 * @param context  The context to use. Usually your
 *                 {@link android.app.Activity} object.
 * @param view
 *                 View to be used.
 * @param text     The text to show. Can be formatted text.
 * @param style    The style with a background and a duration.
 * @param floating true if it'll float.
 */
private static AppMsg makeText(Context context, CharSequence text, Style style, View view, boolean floating, float textSize) {
    AppMsg result = new AppMsg(context);

    view.setBackgroundResource(style.background);

    TextView tv = (TextView) view.findViewById(android.R.id.message);
    if(textSize > 0) tv.setTextSize(textSize);
    tv.setText(text);

    result.mView = view;
    result.mDuration = style.duration;
    result.mFloating = floating;

    return result;
}
 
Example 2
Source File: ListViewFragment.java    From Phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
    final ViewHolder viewHolder;
    if (convertView == null) {
        viewHolder = new ViewHolder();
        convertView = mInflater.inflate(R.layout.list_item, parent, false);
        viewHolder.imageViewIcon = (ImageView) convertView.findViewById(R.id.image_view_icon);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    viewHolder.imageViewIcon.setImageResource(mData.get(position).get(KEY_ICON));
    convertView.setBackgroundResource(mData.get(position).get(KEY_COLOR));

    return convertView;
}
 
Example 3
Source File: CircleIndicator.java    From XERUNG with Apache License 2.0 6 votes vote down vote up
@Override public void onPageSelected(int position) {

        if (mViewpager.getAdapter() == null || mViewpager.getAdapter().getCount() <= 0) {
            return;
        }

        if (mAnimationIn.isRunning()) mAnimationIn.end();
        if (mAnimationOut.isRunning()) mAnimationOut.end();

        View currentIndicator = getChildAt(mCurrentPosition);
        currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);
        mAnimationIn.setTarget(currentIndicator);
        mAnimationIn.start();

        View selectedIndicator = getChildAt(position);
        selectedIndicator.setBackgroundResource(mIndicatorBackgroundResId);
        mAnimationOut.setTarget(selectedIndicator);
        mAnimationOut.start();

        mCurrentPosition = position;
    }
 
Example 4
Source File: PagerSlidingTabStrip.java    From WeCenterMobile-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateTabStyles() {

		for (int i = 0; i < tabCount; i++) {

			View v = tabsContainer.getChildAt(i);

			v.setBackgroundResource(tabBackgroundResId);

			if (v instanceof TextView) {

				TextView tab = (TextView) v;
				tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
				tab.setTypeface(tabTypeface, tabTypefaceStyle);
				tab.setTextColor(tabTextColor);

				// setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
				// pre-ICS-build
				if (textAllCaps) {
					if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
						tab.setAllCaps(true);
					} else {
						tab.setText(tab.getText().toString().toUpperCase(locale));
					}
				}
				if (i == selectedPosition) {
					tab.setTextColor(selectedTabTextColor);
				}
			}
		}

	}
 
Example 5
Source File: MainActivity.java    From ZoomableDraweeView-sample with Apache License 2.0 5 votes vote down vote up
@Override
public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext())
            .inflate(android.R.layout.simple_list_item_1, parent, false);
    v.setBackgroundResource(R.drawable.abc_item_background_holo_light);
    return new ItemHolder(v);
}
 
Example 6
Source File: ChoiceAdapter.java    From currency with GNU General Public License v3.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    ImageView flag;
    TextView name;
    TextView longName;

    // Create a new view
    if (convertView == null)
        convertView = inflater.inflate(resource, parent, false);

    // Find the views
    flag = convertView.findViewById(R.id.flag);
    name = convertView.findViewById(R.id.name);
    longName = convertView.findViewById(R.id.long_name);

    // Update the views
    if (flag != null)
        flag.setImageResource(flags.get(position));

    if (name != null)
        name.setText(names.get(position));

    if (longName != null)
        longName.setText(longNames.get(position));

    // Highlight if selected
    if (selection.contains(position))
        convertView.setBackgroundResource(android.R.color.holo_blue_dark);

    // Clear highlight
    else
        convertView.setBackgroundResource(0);

    return convertView;
}
 
Example 7
Source File: Utils.java    From AlipayPullRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * 点击波纹效果
 */
public static void setBorderlessBackground(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int[] attrs = new int[]{R.attr.selectableItemBackgroundBorderless};
        TypedArray typedArray = view.getContext().obtainStyledAttributes(attrs);
        int backgroundResource = typedArray.getResourceId(0, 0);
        view.setBackgroundResource(backgroundResource);
        typedArray.recycle();
    }
}
 
Example 8
Source File: InCallControls.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
public InCallControls(Context context, AttributeSet attrs, int style) {
    super(context, attrs, style);
    
    if(!isInEditMode()) {
        supportMultipleCalls = SipConfigManager.getPreferenceBooleanValue(getContext(), SipConfigManager.SUPPORT_MULTIPLE_CALLS, false);
    }
    
    final LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
            (int) getResources().getDimension(R.dimen.incall_bottom_bar_height));
    ActionMenuPresenter mActionMenuPresenter = new ActionMenuPresenter(getContext()) {
        public void bindItemView(MenuItemImpl item, MenuView.ItemView itemView) {
            super.bindItemView(item, itemView);
            View actionItemView = (View) itemView;
            actionItemView.setBackgroundResource(R.drawable.btn_compound_background);
        }
    };
    mActionMenuPresenter.setReserveOverflow(true);
    // Full width
    mActionMenuPresenter.setWidthLimit(
            getContext().getResources().getDisplayMetrics().widthPixels, true);
    // We use width limit, no need to limit items.
    mActionMenuPresenter.setItemLimit(20);
    btnMenuBuilder = new MenuBuilder(getContext());
    btnMenuBuilder.setCallback(this);
    MenuInflater inflater = new MenuInflater(getContext());
    inflater.inflate(R.menu.in_call_controls_menu, btnMenuBuilder);
    btnMenuBuilder.addMenuPresenter(mActionMenuPresenter);
    ActionMenuView menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
    menuView.setBackgroundResource(R.drawable.abs__ab_bottom_transparent_dark_holo);
    
    this.addView(menuView, layoutParams);
}
 
Example 9
Source File: MessagesCursorAdapter.java    From OPFPush with Apache License 2.0 5 votes vote down vote up
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
    final View view = LayoutInflater.from(context).inflate(R.layout.item_message, parent, false);

    if (getItemViewType(cursor.getPosition()) == ODD_ITEM) {
        view.setBackgroundResource(R.drawable.odd_message_item_selector);
    }

    return view;
}
 
Example 10
Source File: FadingActionBarHelperBase.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initializeGradient(ViewGroup headerContainer) {
    View gradientView = headerContainer.findViewById(R.id.fab__gradient);
    int gradient = R.drawable.fab__gradient;
    if (mLightActionBar) {
        gradient = R.drawable.fab__gradient_light;
    }
    gradientView.setBackgroundResource(gradient);
}
 
Example 11
Source File: SwipeBackFragment.java    From SwipeBackFragment with Apache License 2.0 5 votes vote down vote up
private void setBackground(View view) {
    if (view != null && view.getBackground() == null) {
        int defaultBg = 0;
        if (_mActivity instanceof SwipeBackActivity) {
            defaultBg = ((SwipeBackActivity) _mActivity).getDefaultFragmentBackground();
        }
        if (defaultBg == 0) {
            int background = getWindowBackground();
            view.setBackgroundResource(background);
        } else {
            view.setBackgroundResource(defaultBg);
        }
    }
}
 
Example 12
Source File: PagerSlidingTabStrip.java    From Pimp_my_Z1 with GNU General Public License v2.0 5 votes vote down vote up
private void updateTabStyles() {

        for (int i = 0; i < tabCount; i++) {

            View v = tabsContainer.getChildAt(i);

            if (v != null) {
                v.setLayoutParams(defaultTabLayoutParams);
                v.setBackgroundResource(tabBackgroundResId);

                if (shouldExpand) {
                    v.setPadding(0, 0, 0, 0);
                } else {
                    v.setPadding(tabPadding, 0, tabPadding, 0);
                }
            }
            if (v instanceof TextView) {

                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                tab.setTypeface(tabTypeface, tabTypefaceStyle);
                tab.setTextColor(tabTextColor);

                // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
                // pre-ICS-build
                if (textAllCaps) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        tab.setAllCaps(true);
                    } else {
                        tab.setText(tab.getText() + "".toUpperCase(locale));
                    }
                }
            }
        }

    }
 
Example 13
Source File: BaseItemAdapter.java    From SimpleAdapterDemo with Apache License 2.0 4 votes vote down vote up
public BaseItemViewHolder setBackgroundResource(@IdRes int id, @DrawableRes int resId) {
    View view = findViewById(id);
    if (view != null)
        view.setBackgroundResource(resId);
    return this;
}
 
Example 14
Source File: ByStartDate.java    From opentasks with Apache License 2.0 4 votes vote down vote up
@Override
public void populateView(View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags)
{
    TextView title = getView(view, android.R.id.title);
    boolean isClosed = cursor.getInt(13) > 0;

    resetFlingView(view);

    if (title != null)
    {
        String text = cursor.getString(5);
        title.setText(text);
        if (isClosed)
        {
            title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        }
        else
        {
            title.setPaintFlags(title.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }
    }

    setDueDate(getView(view, R.id.task_due_date), getView(view, R.id.task_due_image), INSTANCE_DUE_ADAPTER.get(cursor),
            isClosed);

    TextView startDateField = getView(view, R.id.task_start_date);
    if (startDateField != null)
    {
        Time startDate = INSTANCE_START_ADAPTER.get(cursor);

        if (startDate != null)
        {

            startDateField.setVisibility(View.VISIBLE);
            startDateField.setText(new DateFormatter(view.getContext()).format(startDate, DateFormatContext.LIST_VIEW));

            // format time
            startDateField.setTextAppearance(view.getContext(), R.style.task_list_due_text);

            ImageView icon = getView(view, R.id.task_start_image);
            if (icon != null)
            {
                icon.setVisibility(View.VISIBLE);
            }
        }
        else
        {
            startDateField.setText("");
        }
    }

    View divider = getView(view, R.id.divider);
    if (divider != null)
    {
        divider.setVisibility((flags & FLAG_IS_LAST_CHILD) != 0 ? View.GONE : View.VISIBLE);
    }

    // display priority
    int priority = TaskFieldAdapters.PRIORITY.get(cursor);
    View priorityView = getView(view, R.id.task_priority_view_medium);
    priorityView.setBackgroundResource(android.R.color.transparent);
    priorityView.setVisibility(View.VISIBLE);

    if (priority > 0 && priority < 5)
    {
        priorityView.setBackgroundResource(R.color.priority_red);
    }
    if (priority == 5)
    {
        priorityView.setBackgroundResource(R.color.priority_yellow);
    }
    if (priority > 5 && priority <= 9)
    {
        priorityView.setBackgroundResource(R.color.priority_green);
    }

    new ProgressBackgroundView(getView(view, R.id.percentage_background_view))
            .update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor)));

    setColorBar(view, cursor);
    setDescription(view, cursor);
    setOverlay(view, cursor.getPosition(), cursor.getCount());
}
 
Example 15
Source File: VerificationCodeView.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private static void setActive(@NonNull View container) {
  container.setBackgroundResource(R.drawable.labeled_edit_text_background_active);
}
 
Example 16
Source File: CommonHolder.java    From Common with Apache License 2.0 4 votes vote down vote up
/**
 * Set the background to a given resource.
 */
public CommonHolder setBackgroundResource(@IdRes int id, @DrawableRes int resId) {
    View view = getView(id);
    view.setBackgroundResource(resId);
    return this;
}
 
Example 17
Source File: ViewHolder.java    From OXChart with Apache License 2.0 4 votes vote down vote up
public ViewHolder setBackgroundResource(int viewId, int id) {
    View view = getView(viewId);
    view.setBackgroundResource(id);
    return this;
}
 
Example 18
Source File: DrawerUtils.java    From MaterialDrawer-Xamarin with Apache License 2.0 4 votes vote down vote up
/**
 * helper method to handle the headerView
 *
 * @param drawer
 */
public static void handleHeaderView(DrawerBuilder drawer) {
    //use the AccountHeader if set
    if (drawer.mAccountHeader != null) {
        if (drawer.mAccountHeaderSticky) {
            drawer.mStickyHeaderView = drawer.mAccountHeader.getView();
        } else {
            drawer.mHeaderView = drawer.mAccountHeader.getView();
            drawer.mHeaderDivider = drawer.mAccountHeader.mAccountHeaderBuilder.mDividerBelowHeader;
            drawer.mHeaderPadding = drawer.mAccountHeader.mAccountHeaderBuilder.mPaddingBelowHeader;
        }
    }

    //sticky header view
    if (drawer.mStickyHeaderView != null) {
        //add the sticky footer view and align it to the bottom
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1);
        drawer.mStickyHeaderView.setId(R.id.material_drawer_sticky_header);
        drawer.mSliderLayout.addView(drawer.mStickyHeaderView, 0, layoutParams);

        //now align the recyclerView below the stickyFooterView ;)
        RelativeLayout.LayoutParams layoutParamsListView = (RelativeLayout.LayoutParams) drawer.mRecyclerView.getLayoutParams();
        layoutParamsListView.addRule(RelativeLayout.BELOW, R.id.material_drawer_sticky_header);
        drawer.mRecyclerView.setLayoutParams(layoutParamsListView);

        //set a background color or the elevation will not work
        drawer.mStickyHeaderView.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(drawer.mActivity, R.attr.material_drawer_background, R.color.material_drawer_background));

        //add a shadow
        if (Build.VERSION.SDK_INT >= 21) {
            drawer.mStickyHeaderView.setElevation(UIUtils.convertDpToPixel(4, drawer.mActivity));
        } else {
            View view = new View(drawer.mActivity);
            view.setBackgroundResource(R.drawable.material_drawer_shadow_bottom);
            drawer.mSliderLayout.addView(view, RelativeLayout.LayoutParams.MATCH_PARENT, (int) UIUtils.convertDpToPixel(4, drawer.mActivity));
            //now align the shadow below the stickyHeader ;)
            RelativeLayout.LayoutParams lps = (RelativeLayout.LayoutParams) view.getLayoutParams();
            lps.addRule(RelativeLayout.BELOW, R.id.material_drawer_sticky_header);
            view.setLayoutParams(lps);
        }

        //remove the padding of the recyclerView again we have the header on top of it
        drawer.mRecyclerView.setPadding(0, 0, 0, 0);
    }

    // set the header (do this before the setAdapter because some devices will crash else
    if (drawer.mHeaderView != null) {
        if (drawer.mRecyclerView == null) {
            throw new RuntimeException("can't use a headerView without a recyclerView");
        }

        if (drawer.mHeaderPadding) {
            drawer.getAdapter().addHeaderDrawerItems(new ContainerDrawerItem().withView(drawer.mHeaderView).withDivider(drawer.mHeaderDivider).withViewPosition(ContainerDrawerItem.Position.TOP));
        } else {
            drawer.getAdapter().addHeaderDrawerItems(new ContainerDrawerItem().withView(drawer.mHeaderView).withDivider(drawer.mHeaderDivider).withViewPosition(ContainerDrawerItem.Position.NONE));
        }
        //set the padding on the top to 0
        drawer.mRecyclerView.setPadding(drawer.mRecyclerView.getPaddingLeft(), 0, drawer.mRecyclerView.getPaddingRight(), drawer.mRecyclerView.getPaddingBottom());
    }
}
 
Example 19
Source File: BaseViewHolder.java    From imsdk-android with MIT License 2 votes vote down vote up
/**
 * Will set background of a view.
 *
 * @param viewId        The view id.
 * @param backgroundRes A resource to use as a background.
 * @return The BaseViewHolder for chaining.
 */
public BaseViewHolder setBackgroundRes(@IdRes int viewId, @DrawableRes int backgroundRes) {
    View view = getView(viewId);
    view.setBackgroundResource(backgroundRes);
    return this;
}
 
Example 20
Source File: BaseRecyclerAdapter.java    From PLDroidShortVideo with Apache License 2.0 2 votes vote down vote up
/**
 * 设置 View 背景
 *
 * @param id
 * @param drawable
 * @return
 */
public BaseViewHolder setBackground(@IdRes int id, @DrawableRes int drawable) {
    View view = getViewById(id);
    view.setBackgroundResource(drawable);
    return this;
}