Java Code Examples for android.widget.TextView.setBackgroundColor()

The following are Jave code examples for showing how to use setBackgroundColor() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Android-Timeline-View   File: VerticalRecyclerViewAdapter.java   View Source Code Vote up 7 votes
public VerticalRecyclerViewHolder(View view) {
    super(view);

    time = (TextView) view.findViewById(R.id.tv_timeline_time);
    header = (TextView) view.findViewById(R.id.tv_timeline_header);
    header.setVisibility(View.INVISIBLE);

    timelineindicator_container = (RelativeLayout) view.findViewById(R.id.container_timeline_indicator);
    timelineindicator_line = (TextView) view.findViewById(R.id.tv_timeline_indicator_line);

    /*apply configs*/
    time.setTextColor(Color.parseColor(TimeLineConfig.getTimelineHeaderTextColour()));
    time.setTextSize(TimeLineConfig.getTimelineHeaderSize());
    timelineindicator_line.setBackgroundColor(Color.parseColor(TimeLineConfig.getTimelineIndicatorLineColour()));
    timelineindicator_container.setBackgroundColor(Color.parseColor(TimeLineConfig.getTimelineIndicatorBackgroundColour()));

    recyclerView = (RecyclerView) view.findViewById(R.id.rv_horizontal_timeline);

    LinearLayoutManager recyclerViewLayoutManager = new LinearLayoutManager(context);
    recyclerView.setLayoutManager(recyclerViewLayoutManager);
    LinearLayoutManager horizontalLinearLayoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(horizontalLinearLayoutManager);
}
 
Example 2
Project: AdvancedTextView   File: ActionMenu.java   View Source Code Vote up 6 votes
/**
 * 创建MenuItem
 */
private View createMenuItem(final String itemTitle) {
    final TextView menuItem = new TextView(mContext);
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    params.leftMargin = params.rightMargin = mMenuItemMargin;
    menuItem.setLayoutParams(params);

    menuItem.setTextSize(14);
    menuItem.setTextColor(mMenuItemTextColor);
    menuItem.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));
    menuItem.setGravity(Gravity.CENTER);
    menuItem.setText(itemTitle);
    menuItem.setTag(itemTitle);

    return menuItem;
}
 
Example 3
Project: ucar-weex-core   File: WXPickersModule.java   View Source Code Vote up 6 votes
private TextView makeTitleView(Context context, Map<String, Object> options) {
    String text = getOption(options, KEY_TITLE, null);
    if (text == null) {
        return null;
    }
    TextView textView = new TextView(context);
    textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
    int padding = WXViewUtils.dip2px(12);
    textView.setPadding(padding, padding, padding, padding);
    textView.getPaint().setFakeBoldText(true);
    textView.setBackgroundColor(getColor(options, KEY_TITLE_BACKGROUND_COLOR, Color.TRANSPARENT));
    textView.setTextColor(getColor(options, KEY_TITLE_COLOR, Color.BLACK));
    textView.setText(text);
    return textView;
}
 
Example 4
Project: Musicoco   File: MainSheetsController.java   View Source Code Vote up 6 votes
private void updateTextAndColor(TextView categoryView, int count, TextView countView, int[] colors) {

        categoryView.setBackgroundColor(colors[2]);
        categoryView.setTextColor(colors[3]);

        GradientDrawable countD = new GradientDrawable();
        countD.setColor(colors[0]);
        countD.setCornerRadius(countView.getHeight() / 2);
        countView.setBackground(countD);
        countView.setTextColor(colors[1]);

        int c = count;
        if (countView == mCountRecent) {
            int recent = activity.getResources().getInteger(R.integer.sheet_recent_count);
            c = count > recent ? recent : c;
        }
        countView.setText(String.valueOf(c));

    }
 
Example 5
Project: SmartRefreshLayout   File: FunGameHeader.java   View Source Code Vote up 5 votes
private TextView createMaskTextView(Context context, String text, int textSize, int gravity) {
    TextView maskTextView = new TextView(context);
    maskTextView.setTextColor(Color.BLACK);
    maskTextView.setBackgroundColor(Color.WHITE);
    maskTextView.setGravity(gravity | Gravity.CENTER_HORIZONTAL);
    maskTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    maskTextView.setText(text);
    return maskTextView;
}
 
Example 6
Project: Musicoco   File: PlayThemeCustomActivity.java   View Source Code Vote up 5 votes
private void update() {
    viewHolder.imageSwitch.setImageResource(dataHolder.images[select]);
    for (int i = 0; i < viewHolder.texts.length; i++) {
        TextView view = viewHolder.texts[i];
        if (i == select) {
            view.setTextColor(selectTC);
            view.setBackgroundColor(selectBC);
        } else {
            view.setTextColor(mainTC);
            view.setBackgroundColor(Color.TRANSPARENT);
        }
    }
}
 
Example 7
Project: grox   File: MainActivity.java   View Source Code Vote up 5 votes
private void updateUI(State newState) {
  final TextView label = (TextView) findViewById(R.id.label);
  label.setBackgroundColor(getResources().getColor(android.R.color.background_light));
  label.setText("");
  if (newState.isRefreshing) {
    label.setText("↺");
  } else if (newState.error != null) {
    label.setText(newState.error);
  } else if (newState.color != State.INVALID_COLOR) {
    label.setBackgroundColor(newState.color);
  }
}
 
Example 8
Project: GitHub   File: IndicatorView.java   View Source Code Vote up 5 votes
/**
 * 向父容器中添加TextView
 *
 * @param text  TextView显示文字
 * @param color TextView的背景颜色,如:"#FADBCC"
 */
private void addTextView(Context context, String text, int color) {
    TextView textView = new TextView(context);
    textView.setBackgroundColor(color);
    textView.setText(text);
    textView.setTextColor(textColor);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
    textView.setSingleLine();
    textView.setGravity(Gravity.CENTER);
    textView.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0F));
    this.addView(textView);
}
 
Example 9
Project: GitHub   File: PinnedSectionListActivity.java   View Source Code Vote up 5 votes
@Override public View getView(int position, View convertView, ViewGroup parent) {
    TextView view = (TextView) super.getView(position, convertView, parent);
    view.setTextColor(Color.DKGRAY);
    view.setTag("" + position);
    Item item = getItem(position);
    if (item.type == Item.SECTION) {
        //view.setOnClickListener(PinnedSectionListActivity.this);
        view.setBackgroundColor(parent.getResources().getColor(COLORS[item.sectionPosition % COLORS.length]));
    }
    return view;
}
 
Example 10
Project: GitHub   File: StaggeredGridFragment.java   View Source Code Vote up 5 votes
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    TextView view = new TextView(getActivity());
    view.setGravity(Gravity.CENTER);
    view.setBackgroundColor(Color.argb(125, 255, 0, 0));
    MyViewHolder mViewHolder = new MyViewHolder(view);
    parent.addView(view);
    return mViewHolder;
}
 
Example 11
Project: OpenAPK   File: AboutActivity.java   View Source Code Vote up 5 votes
private void setScreenElements() {
    TextView header = (TextView) findViewById(R.id.header);
    TextView text = (TextView) findViewById(R.id.app_name);
    ImageView icon = (ImageView) findViewById(R.id.about_icon);

    header.setBackgroundColor(AppPreferences.get(this).getPrimaryColor());
    text.setText(String.format("%s %s", getResources().getString(R.string.app_name), OtherUtils.getAppVersionName(getApplicationContext())));
    if (AppPreferences.get(this).getTheme().equals("0")) {
        icon.setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.grey_two));
    }
}
 
Example 12
Project: ArtOfAndroid   File: Demo2Activity.java   View Source Code Vote up 5 votes
private void initView() {
    LayoutInflater layoutInflater = getLayoutInflater();
    mListContainer = (HorizontalScrollViewEx2) findViewById(R.id.container);
    int screenWidth = MyUtil.getScreenMetrics(this).widthPixels;
    for (int i = 0; i < 3; i++) {
        ViewGroup layout = (ViewGroup) layoutInflater.inflate(R.layout.content_layout2, mListContainer, false);
        layout.getLayoutParams().width = screenWidth;
        TextView textView = (TextView) layout.findViewById(R.id.title);
        textView.setText("page " + (i + 1));
        textView.setBackgroundColor(Color.rgb(255 / (i + 1), 255 / (i + 1), 0));
        createList(layout);
        mListContainer.addView(layout);
    }
}
 
Example 13
Project: GitHub   File: SampleParentActivity.java   View Source Code Vote up 5 votes
protected View getColoredView(int bgColor, String msg) {
    TextView tv = new TextView(this);
    tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    tv.setText(msg);
    tv.setBackgroundColor(bgColor);
    tv.setPadding(10, 10, 10, 10);
    tv.setTextColor(getContrastColor(bgColor));
    return tv;
}
 
Example 14
Project: boohee_v5.6   File: DietKeyboard.java   View Source Code Vote up 5 votes
public void initUnit() {
    if (this.mUnits != null && this.mUnits.size() != 0 && this.currentUnit != null) {
        LayoutParams parms = new LayoutParams(-1, -2, 1.0f);
        this.ll_diet_unit.removeAllViews();
        this.unitTextViews.clear();
        for (int i = 0; i < this.mUnits.size(); i++) {
            TextView textView = new TextView(getContext());
            textView.setText(((Unit) this.mUnits.get(i)).unit_name);
            textView.setGravity(17);
            textView.setTextSize(18.0f);
            textView.setTextColor(getResources().getColor(R.color.color_light));
            textView.setBackgroundColor(getResources().getColor(R.color.color_divider));
            textView.setSingleLine(true);
            textView.setEllipsize(TruncateAt.END);
            textView.setId(i);
            textView.setOnClickListener(new UnitListener());
            if (TextUtils.equals(((Unit) this.mUnits.get(i)).unit_name, this.currentUnit
                    .unit_name)) {
                textView.setTextColor(-1);
                textView.setBackgroundColor(getResources().getColor(R.color.color_bg_number));
            }
            this.unitTextViews.add(textView);
            this.ll_diet_unit.addView(textView, parms);
        }
        if (this.mAmount < 0.0f) {
            this.mAmount = 100.0f;
        }
        this.mGram = Float.parseFloat(this.currentUnit.eat_weight) * this.mAmount;
        this.mCalory = this.mWeight * this.mGram;
        this.txt_value.setText(this.mAmount + "");
        swithTxt();
    }
}
 
Example 15
Project: Android-GuideView   File: MainActivity.java   View Source Code Vote up 5 votes
private TextView createTextView() {
    TextView textView = new TextView(this);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    textView.setTextColor(Color.CYAN);
    textView.setTextSize(30f);
    textView.setBackgroundColor(Color.RED);
    textView.setText("tips view");
    return textView;
}
 
Example 16
Project: social-login-helper   File: InstagramDialog.java   View Source Code Vote up 5 votes
/**
 * Set title of dialog
 */
private void setUpTitle() {
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  mTitle = new TextView(getContext());
  mTitle.setText("Instagram");
  mTitle.setTextColor(Color.WHITE);
  mTitle.setTypeface(Typeface.DEFAULT_BOLD);
  mTitle.setBackgroundColor(Color.BLACK);
  mTitle.setPadding(MARGIN + PADDING, MARGIN, MARGIN, MARGIN);
  mContent.addView(mTitle);
}
 
Example 17
Project: HelloTV   File: MainFragment.java   View Source Code Vote up 5 votes
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
    TextView view = new TextView(parent.getContext());
    view.setLayoutParams(new ViewGroup.LayoutParams(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT));
    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.setBackgroundColor(getResources().getColor(R.color.default_background));
    view.setTextColor(Color.WHITE);
    view.setGravity(Gravity.CENTER);
    return new ViewHolder(view);
}
 
Example 18
Project: Phoenix-for-VK   File: TextInputLayout.java   View Source Code Vote up 5 votes
private void prepareEditText(TextView editText) {
    int dp2 = (int) dpToPx(2f, getContext());
    int dp4 = (int) dpToPx(4f, getContext());

    editText.setBackgroundColor(Color.TRANSPARENT);
    editText.setPadding(dp2, dp4, dp2, dp4);
}
 
Example 19
Project: SeizeRecyclerView   File: FilmCommentAViewHolder.java   View Source Code Vote up 4 votes
public FilmCommentAViewHolder(ViewGroup parent) {
    super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_film_comment, parent, false));
    commentTv = (TextView) itemView.findViewById(R.id.item_film_comment_tv);
    commentTv.setBackgroundColor(Color.GRAY);
    commentTv.setOnClickListener(this);
}
 
Example 20
Project: PullListView   File: AddExtraHeaderFragment2.java   View Source Code Vote up 2 votes
private void initView(View v) {

        plvData = (PullListView) v.findViewById(R.id.plv_data);

        plvData.addPullHeaderView();

        TextView header = new TextView(getActivity());

        header.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 150));

        header.setGravity(Gravity.CENTER);

        header.setBackgroundColor(Color.parseColor("#4db6ac"));

        header.setText("我是额外的Header,我在下拉刷新Header下面");

        plvData.addHeaderView(header);


        plvData.setOnRefreshListener(new PullListView.OnRefreshListener() {

            @Override
            public void onRefresh() {
                DataUtil.getData(true, adapter, plvData);

            }
        });

        plvData.setOnGetMoreListener(new PullListView.OnGetMoreListener() {

            @Override
            public void onGetMore() {
                DataUtil.getData(false, adapter, plvData);

            }
        });

        adapter = new ArrayAdapter<>(getActivity(), R.layout.list_item);
        plvData.setAdapter(adapter);

        plvData.performRefresh();

    }