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

The following are Jave code examples for showing how to use setBackgroundResource() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: Buildable.java   Source Code and License Vote up 7 votes
protected BuildBean buildLoading(BuildBean bean) {
    Dialog dialog = new Dialog(bean.mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    bean.dialog = dialog;
    View root;
    if (bean.isVertical) {
        root = View.inflate(bean.mContext, R.layout.dialogui_loading_vertical, null);
    } else {
        root = View.inflate(bean.mContext, R.layout.dialogui_loading_horizontal, null);
    }
    View llBg = (View) root.findViewById(R.id.dialogui_ll_bg);
    ProgressBar pbBg = (ProgressBar) root.findViewById(R.id.pb_bg);
    TextView tvMsg = (TextView) root.findViewById(R.id.dialogui_tv_msg);
    tvMsg.setText(bean.msg);
    if (bean.isWhiteBg) {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_wihte_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_rotate_mum));
        tvMsg.setTextColor(bean.mContext.getResources().getColor(R.color.text_black));
    } else {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_gray_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_rotate_mum_light));
        tvMsg.setTextColor(Color.WHITE);
    }
    bean.dialog.setContentView(root);
    return bean;
}
 
Example 2
Project: EsperantoRadio   File: AlleUdsendelserAtilAA_frag.java   Source Code and License Vote up 6 votes
@Override
public View getView(int position, View v, ViewGroup parent) {
  try {
    if (v == null) v = getLayoutInflater(null).inflate(R.layout.listeelem_2linjer, parent, false);
    AQuery aq = new AQuery(v);

    Programserie ps = liste.get(position);
    aq.id(R.id.linje1).text(ps.titel).typeface(App.skrift_gibson_fed).textColor(Color.BLACK);
    int n = ps.antalUdsendelser;
    String txt = n==0 ? "" : n==1 ? n + " udsendelse" : n + " udsendelser";
    aq.id(R.id.linje2).text(txt).typeface(App.skrift_gibson);
    aq.id(R.id.stiplet_linje).visibility(position == 0 ? View.INVISIBLE : View.VISIBLE);
    v.setBackgroundResource(0);


  } catch (Exception e) {
    Log.rapporterFejl(e);
  }

  return v;
}
 
Example 3
Project: Carousel   File: CarouselView.java   Source Code and License Vote up 6 votes
/**
 * 添加底部Indicator点
 */
private void addIndicator() {
    llIndicator.removeAllViews();
    indicatorViews.clear();
    for (int i = 0; i < carouselPageAdapter.getCount(); i++) {
        View indicatorView = new View(context);
        indicatorView.setBackgroundResource(i == 0 ? indicatorSelected : indicatorUnselected);
        llIndicator.addView(indicatorView);
        LinearLayout.MarginLayoutParams params = (LinearLayout.MarginLayoutParams) indicatorView.getLayoutParams();
        if (i == 0 && indicatorSelectedWidth > 0 && indicatorSelectedHeight > 0) {
            params.width = indicatorSelectedWidth;
            params.height = indicatorSelectedHeight;
        } else if (i > 0 && indicatorUnSelectedWidth > 0 && indicatorUnSelectedHeight > 0) {
            params.width = indicatorUnSelectedWidth;
            params.height = indicatorUnSelectedHeight;
        } else {
            params.width = indicatorWidth;
            params.height = indicatorHeight;
        }
        params.leftMargin = indicatorPadding / 2;
        params.rightMargin = indicatorPadding / 2;
        indicatorView.setLayoutParams(params);
        indicatorViews.add(indicatorView);
    }
}
 
Example 4
Project: KUtils-master   File: Buildable.java   Source Code and License Vote up 6 votes
protected BuildBean buildMdLoadingVertical(BuildBean bean) {
    AlertDialog.Builder builder = new AlertDialog.Builder(bean.mContext);
    View root = View.inflate(bean.mContext, R.layout.dialogui_loading_vertical, null);
    View llBg = (View) root.findViewById(R.id.dialogui_ll_bg);
    ProgressBar pbBg = (ProgressBar) root.findViewById(R.id.pb_bg);
    TextView tvMsg = (TextView) root.findViewById(R.id.dialogui_tv_msg);
    tvMsg.setText(bean.msg);
    if (bean.isWhiteBg) {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_wihte_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_rotate_mum));
        tvMsg.setTextColor(bean.mContext.getResources().getColor(R.color.text_black));
    } else {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_gray_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_rotate_mum_light));
        tvMsg.setTextColor(Color.WHITE);
    }
    builder.setView(root);
    AlertDialog dialog = builder.create();
    bean.alertDialog = dialog;
    return bean;
}
 
Example 5
Project: KUtils-master   File: Buildable.java   Source Code and License Vote up 6 votes
protected BuildBean buildLoadingHorizontal(BuildBean bean) {
    Dialog dialog = new Dialog(bean.mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    bean.dialog = dialog;

    View root = View.inflate(bean.mContext, R.layout.dialogui_loading_horizontal, null);
    View llBg = (View) root.findViewById(R.id.dialogui_ll_bg);
    ProgressBar pbBg = (ProgressBar) root.findViewById(R.id.pb_bg);
    TextView tvMsg = (TextView) root.findViewById(R.id.dialogui_tv_msg);
    tvMsg.setText(bean.msg);
    if (bean.isWhiteBg) {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_wihte_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_shape_progress));
        tvMsg.setTextColor(bean.mContext.getResources().getColor(R.color.text_black));
    } else {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_gray_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_shape_progress_light));
        tvMsg.setTextColor(Color.WHITE);
    }
    bean.dialog.setContentView(root);
    return bean;
}
 
Example 6
Project: KUtils   File: Buildable.java   Source Code and License Vote up 6 votes
protected BuildBean buildMdLoadingHorizontal(BuildBean bean) {
    AlertDialog.Builder builder = new AlertDialog.Builder(bean.mContext);
    View root = View.inflate(bean.mContext, R.layout.dialogui_loading_horizontal, null);
    View llBg = (View) root.findViewById(R.id.dialogui_ll_bg);
    ProgressBar pbBg = (ProgressBar) root.findViewById(R.id.pb_bg);
    TextView tvMsg = (TextView) root.findViewById(R.id.dialogui_tv_msg);
    tvMsg.setText(bean.msg);
    if (bean.isWhiteBg) {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_wihte_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_shape_progress));
        tvMsg.setTextColor(bean.mContext.getResources().getColor(R.color.text_black));
    } else {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_gray_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_shape_progress_light));
        tvMsg.setTextColor(Color.WHITE);
    }
    builder.setView(root);
    AlertDialog dialog = builder.create();
    bean.alertDialog = dialog;
    return bean;
}
 
Example 7
Project: GitHub   File: CircleIndicator.java   Source Code and License Vote up 5 votes
@Override public void onPageSelected(int position) {

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

            if (mAnimatorIn.isRunning()) {
                mAnimatorIn.end();
                mAnimatorIn.cancel();
            }

            if (mAnimatorOut.isRunning()) {
                mAnimatorOut.end();
                mAnimatorOut.cancel();
            }

            View currentIndicator;
            if (mLastPosition >= 0 && (currentIndicator = getChildAt(mLastPosition)) != null) {
                currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);
                mAnimatorIn.setTarget(currentIndicator);
                mAnimatorIn.start();
            }

            View selectedIndicator = getChildAt(position);
            if (selectedIndicator != null) {
                selectedIndicator.setBackgroundResource(mIndicatorBackgroundResId);
                mAnimatorOut.setTarget(selectedIndicator);
                mAnimatorOut.start();
            }
            mLastPosition = position;
        }
 
Example 8
Project: SuperRecyclerView   File: SuperRecyclerAdapter.java   Source Code and License Vote up 5 votes
private void background(View view, Object object) {
    if (object.getClass().equals(Integer.class)) {
        view.setBackgroundResource(Integer.parseInt(object.toString()));
    } else if (object.getClass().equals(Drawable.class)) {
        view.setBackgroundDrawable((Drawable) object);
    } else {
        throw new IllegalStateException("The parameter method need be Integer, Drawable");
    }
}
 
Example 9
Project: PreviewSeekBar-master   File: PreviewGeneralLayout.java   Source Code and License Vote up 5 votes
private void init(Context context, AttributeSet attrs) {
    TypedValue outValue = new TypedValue();

    getContext().getTheme().resolveAttribute(R.attr.colorAccent, outValue, true);
    tintColor = ContextCompat.getColor(context, outValue.resourceId);

    // Create morph view
    morphView = new View(getContext());
    morphView.setBackgroundResource(R.drawable.previewseekbar_morph);

    // Create frame view for the circular reveal
    frameView = new View(getContext());
    delegate = new PreviewDelegate(this);
}
 
Example 10
Project: letv   File: TabPageIndicator.java   Source Code and License Vote up 5 votes
public void setCurrentItem(int item) {
    if (this.mViewPager == null) {
        throw new IllegalStateException("ViewPager has not been bound.");
    }
    this.mSelectedTabIndex = item;
    if (this.mSelectedTabIndex != item) {
        this.mViewPager.setCurrentItem(item);
    }
    int tabCount = this.mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        boolean isSelected;
        View child = this.mTabLayout.getChildAt(i);
        if (i == item) {
            isSelected = true;
        } else {
            isSelected = false;
        }
        child.setSelected(isSelected);
        if (isSelected) {
            animateToTab(item);
            ((TabView) child).setTextColor(this.mContext.getResources().getColor(R.color.letv_color_ffef534e));
            child.setBackgroundResource(R.drawable.tab_indicator_bg);
        } else {
            ((TabView) child).setTextColor(this.mContext.getResources().getColor(R.color.letv_color_ff444444));
            child.setBackgroundDrawable(null);
        }
        if (i == 0 && (child instanceof FrameLayout)) {
            ((FrameLayout) child).getChildAt(0).setBackgroundDrawable(null);
        }
    }
}
 
Example 11
Project: boohee_v5.6   File: PagerSlidingTabStrip.java   Source Code and License Vote up 5 votes
private void updateTabStyles() {
    for (int i = 0; i < this.tabCount; i++) {
        View v = this.tabsContainer.getChildAt(i);
        v.setBackgroundResource(this.tabBackgroundResId);
        if ((v instanceof FrameLayout) && ((FrameLayout) v).getChildCount() > 0) {
            View textView = ((FrameLayout) v).getChildAt(0);
            if (textView instanceof TextView) {
                updateTextTab(i, textView);
            }
        }
        if (v instanceof TextView) {
            updateTextTab(i, v);
        }
    }
}
 
Example 12
Project: EsperantoRadio   File: Favoritprogrammer_frag.java   Source Code and License Vote up 5 votes
@Override
public View getView(int position, View v, ViewGroup parent) {
  try {
    if (v == null) v = getActivity().getLayoutInflater().inflate(R.layout.listeelem_2linjer, parent, false);
    AQuery aq = new AQuery(v);
    Pair elem = (Pair) liste.get(position);
    Backend b = (Backend) elem.first;
    Object obj = elem.second;
    if (obj instanceof Programserie) {
      Programserie ps = (Programserie) obj;
      aq.id(R.id.linje1).text(ps.titel).typeface(App.skrift_gibson_fed).textColor(Color.BLACK);
      int n = b.favoritter.getAntalNyeUdsendelser(ps.slug);
      String txt = (n == 1 ? n + getString(R.string._ny_udsendelse) : n + getString(R.string._nye_udsendelser));
      aq.id(R.id.linje2).text(txt).typeface(App.skrift_gibson);
      aq.id(R.id.stiplet_linje).visibility(position == 0 ? View.INVISIBLE : View.VISIBLE);
    } else {
      Udsendelse udsendelse = (Udsendelse) obj;
      aq.id(R.id.linje1).text(Datoformater.datoformat.format(udsendelse.startTid)).typeface(App.skrift_gibson);
      aq.id(R.id.linje2).text(udsendelse.titel).typeface(App.skrift_gibson);
      aq.id(R.id.stiplet_linje).visibility(View.VISIBLE);
    }
    v.setBackgroundResource(0);


  } catch (Exception e) {
    Log.rapporterFejl(e);
  }

  return v;
}
 
Example 13
Project: XinFramework   File: SupportFragmentDelegate.java   Source Code and License Vote up 5 votes
public void setBackground(View view) {
    if ((mFragment.getTag() != null && mFragment.getTag().startsWith("android:switcher:")) ||
            mRootStatus != STATUS_UN_ROOT ||
            view.getBackground() != null) {
        return;
    }

    int defaultBg = mSupport.getSupportDelegate().getDefaultFragmentBackground();
    if (defaultBg == 0) {
        int background = getWindowBackground();
        view.setBackgroundResource(background);
    } else {
        view.setBackgroundResource(defaultBg);
    }
}
 
Example 14
Project: garras   File: MasterFragmentDelegate.java   Source Code and License Vote up 5 votes
public void onViewCreated(View view, Bundle savedInstanceState) {
    // Use window background as the top level background.
    // Note: The view is an instance of NoSaveStateFrameLayout,
    // which is inserted between the Fragment's view and its container by FragmentManager.
    TypedValue outValue = new TypedValue();
    getFragmentContext().getTheme().resolveAttribute(android.R.attr.windowBackground, outValue, true);
    view.setBackgroundResource(outValue.resourceId);
    // Set the "clickable" of the fragment's root view to true to avoid
    // touch events to be passed to the views behind the fragment.
    view.setClickable(true);
    if (getFragmentMaster() != null) {
        getFragmentMaster().dispatchFragmentViewCreated(mMasterFragment);
    }
}
 
Example 15
Project: Closet   File: ClosetFragment.java   Source Code and License Vote up 4 votes
private void setupUnitCategory(HomeCategoryEntity homeCategoryEntity, final int index) {
    MasterCategoryEntity categoryEntity = homeCategoryEntity.getCategoryEntity();
    String cateName = categoryEntity.getCateName();
    final int picResId = categoryEntity.getPicResId();
    final List<ProductEntity> productEntityList = homeCategoryEntity.getProductEntityList();

    LinearLayout unitContainer = new LinearLayout(getContext());
    unitContainer.setOrientation(LinearLayout.VERTICAL);
    unitContainer.setGravity(Gravity.CENTER_VERTICAL);
    unitContainer.setBackgroundResource(R.color.bg_default_category);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, DisplayUtil.dip2px(getResources().getInteger(R.integer.category_unit_height), getContext()));
    layoutParams.gravity = Gravity.CENTER;
    unitContainer.setLayoutParams(layoutParams);

    final ImageView imgIcon = new ImageView(getAttachActivity());
    int length = DisplayUtil.dip2px(32, getAttachActivity());
    LinearLayout.LayoutParams iconLp = new LinearLayout.LayoutParams(length, length);
    iconLp.gravity = Gravity.CENTER_HORIZONTAL;
    imgIcon.setLayoutParams(iconLp);
    imgIcon.setImageResource(picResId);


    final TextView tvCategory = new TextView(getContext());
    LinearLayout.LayoutParams tvLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    tvLp.gravity = Gravity.CENTER_HORIZONTAL;
    tvCategory.setLayoutParams(tvLp);
    tvCategory.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
    tvCategory.setTextColor(getAttachActivity().getResources().getColor(R.color.font_red));
    tvCategory.setText(cateName);
    tvCategory.setVisibility(View.GONE);

    View lineView = new View(getContext());
    LinearLayout.LayoutParams lineLp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1);
    lineView.setLayoutParams(lineLp);
    lineView.setBackgroundResource(R.color.line);

    mUnitCategoryLayoutList.add(unitContainer);
    mTvCategoryNameList.add(tvCategory);
    mImgCategoryIconList.add(imgIcon);

    unitContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            reactionToClickCategory(index, productEntityList);
        }
    });

    unitContainer.addView(imgIcon);
    unitContainer.addView(tvCategory);
    mContainerCategory.addView(unitContainer);
    mContainerCategory.addView(lineView);
}
 
Example 16
Project: OSchina_resources_android   File: TeamReplyAdapter.java   Source Code and License Vote up 4 votes
private void setReplies(Context context, TeamReply item, ViewHolder vh) {
    List<TeamReply> replies = item.getReplies();
    vh.relies.removeAllViews();
    if (replies == null || replies.size() <= 0) {
        vh.relies.setVisibility(View.GONE);
    } else {
        vh.relies.setVisibility(View.VISIBLE);

        // add count layout
        View countView = getLayoutInflater(context).inflate(
                R.layout.list_cell_reply_count, null, false);
        TextView count = (TextView) countView
                .findViewById(R.id.tv_comment_reply_count);
        count.setText(context.getResources().getString(
                R.string.comment_reply_count, replies.size()));
        vh.relies.addView(countView);

        for (TeamReply teamReply : replies) {
            View replyItemView = getLayoutInflater(
                    context).inflate(R.layout.list_cell_team_reply_refers,
                    null, false);
            replyItemView.setBackgroundResource(R.drawable.comment_background);

            AvatarView avatarView = (AvatarView) replyItemView.findViewById(R.id.iv_avatar);
            avatarView.setAvatarUrl(teamReply.getAuthor().getPortrait());
            TextView name = (TextView) replyItemView.findViewById(R.id.tv_name);
            name.setText(teamReply.getAuthor().getName());
            TweetTextView content = (TweetTextView) replyItemView.findViewById(R.id.tv_content);
            setContent(content, HTMLUtil.delHTMLTag(teamReply.getContent()));
            TextView time = (TextView) replyItemView.findViewById(R.id.tv_time);
            time.setText(StringUtils.formatSomeAgo(teamReply.getCreateTime()));
            TextView from = (TextView) replyItemView.findViewById(R.id.tv_from);
            if (StringUtils.isEmpty(teamReply.getAppName())) {
                from.setVisibility(View.GONE);
            } else {
                from.setVisibility(View.VISIBLE);
                from.setText(teamReply.getAppName());
            }
            vh.relies.addView(replyItemView);
        }
    }
}
 
Example 17
Project: TextReader   File: EasyLVHolder.java   Source Code and License Vote up 4 votes
@Override
public EasyLVHolder setBackgroundColorRes(int viewId, int colorRes) {
    View view = getView(viewId);
    view.setBackgroundResource(colorRes);
    return this;
}
 
Example 18
Project: JueDiQiuSheng   File: ViewHolder.java   Source Code and License Vote up 4 votes
public ViewHolder setBackgroundRes(int viewId, int backgroundRes)
{
    View view = getView(viewId);
    view.setBackgroundResource(backgroundRes);
    return this;
}
 
Example 19
Project: BaseAdapterRel   File: ViewHolder.java   Source Code and License Vote up 4 votes
public ViewHolder setBackgroundRes(int viewId, int backgroundRes)
{
    View view = getView(viewId);
    view.setBackgroundResource(backgroundRes);
    return this;
}
 
Example 20
Project: GitHub   File: BaseViewHolder.java   Source Code and License Vote up 2 votes
/**
 * 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;
}