Example usage for android.widget TextView setBackgroundResource

List of usage examples for android.widget TextView setBackgroundResource

Introduction

In this page you can find the example usage for android.widget TextView setBackgroundResource.

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:com.rolmex.android.nemalltone.fragment.ViewPageFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    context = getActivity();/*from  w w w.  ja  va2  s .c  o  m*/
    View mView = inflater.inflate(R.layout.view_main, null);

    // 
    int[] attrs = { android.R.attr.windowBackground };
    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.windowBackground, outValue, true);
    TypedArray style = context.getTheme().obtainStyledAttributes(outValue.resourceId, attrs);
    windowBackground = style.getDrawable(0);
    style.recycle();

    // head_layout = (RelativeLayout)mView.findViewById(R.id.head_layout);
    // head_layout.setBackground(windowBackground);
    // ??
    table_layout = (LinearLayout) mView.findViewById(R.id.table_layout);
    //        table_layout.setBackground(windowBackground);
    //        table_layout.setBackgroundResource(context.getResources().getColor(R.color.white));
    DisplayMetrics dm = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
    // ??veiwPager?2
    width = dm.widthPixels / 2 - 1;
    hsv = (HorizontalScrollView) mView.findViewById(R.id.main_ho_sv);
    hfl = (FrameLayout) mView.findViewById(R.id.main_fl);
    TextView placeView = new TextView(context);
    placeView.setLayoutParams(new FrameLayout.LayoutParams(width * 2, 10));
    placeView.setBackgroundResource(R.color.half_white);
    hfl.addView(placeView);
    slidView = new TextView(context);
    slidView.setLayoutParams(new FrameLayout.LayoutParams(width, 10));
    slidView.setBackgroundResource(R.color.holo_blue);
    hfl.addView(slidView);
    home_view = (TextView) mView.findViewById(R.id.home_mian_view);
    always_view = (TextView) mView.findViewById(R.id.home_always_view);

    showLeft = (Button) mView.findViewById(R.id.showLeft);
    showRight = (Button) mView.findViewById(R.id.showRight);

    mPager = (JazzyViewPager) mView.findViewById(R.id.pager);

    /**
     * ?
     */
    mPager.setTransitionEffect(TransitionEffect.FlipHorizontal);

    PageFragment1 page1 = new PageFragment1();
    PageFragment2 page2 = new PageFragment2();
    pagerItemList.add(page1);
    pagerItemList.add(page2);
    mAdapter = new MyAdapter(getFragmentManager());

    mPager.setAdapter(mAdapter);
    mPager.setPageMargin(30);

    mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            updateTableBg(position);
            slidView.setTranslationX(width * position);
            if (myPageChangeListener != null)
                myPageChangeListener.onPageSelected(position);

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
            if (arg1 > 0.0)
                slidView.setTranslationX(width * arg1);
        }

        @Override
        public void onPageScrollStateChanged(int position) {

        }
    });

    return mView;
}

From source file:com.android.firewall.FirewallListPage.java

private TextView getTabView(int width, int height, String title) {
    TextView view = new TextView(this);
    view.setMinimumWidth(width);//from  www  .j  a  v  a  2  s .c  om
    view.setMinimumHeight(height);
    view.setGravity(Gravity.CENTER);
    view.setBackgroundResource(R.drawable.tab_indicator_holo);
    view.setText(title);
    return view;
}

From source file:net.yanzm.mth.MaterialTabHost.java

/**
 * add new tab with title text//  w  w  w.  j  a  v  a 2 s.c  om
 *
 * @param title title text
 */
public void addTab(CharSequence title) {
    int layoutId = getLayoutId(type);
    TextView tv = (TextView) inflater.inflate(layoutId, tabWidget, false);
    tv.setText(title);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tv.setBackgroundResource(R.drawable.mth_tab_widget_background_ripple);

    } else {
        // create background using colorControlActivated
        StateListDrawable d = new StateListDrawable();
        d.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(colorControlActivated));
        d.setAlpha(180);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            tv.setBackground(d);
        } else {
            tv.setBackgroundDrawable(d);
        }
    }

    int tabId = tabWidget.getTabCount();

    addTab(newTabSpec(String.valueOf(tabId)).setIndicator(tv).setContent(android.R.id.tabcontent));
}

From source file:com.orange.ocara.ui.view.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setText(title);/*from w w w  . ja va 2  s  .  c  o  m*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setBackgroundResource(tabBackgroundResId);
    tab.setTextColor(tabTextColor);
    tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
    tab.setEllipsize(TextUtils.TruncateAt.MARQUEE);
    tab.setAllCaps(true);

    addTab(position, tab);
}

From source file:com.google.android.gcm.demo.ui.GroupsFragment.java

@Override
public void refresh() {
    float density = getActivity().getResources().getDisplayMetrics().density;
    SimpleArrayMap<String, Sender> senders = mSenders.getSenders();
    LinearLayout sendersList = new LinearLayout(getActivity());
    sendersList.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < senders.size(); i++) {
        Sender sender = senders.valueAt(i);
        if (sender.groups.size() > 0) {
            LinearLayout senderRow = (LinearLayout) getActivity().getLayoutInflater()
                    .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
            ImageView senderIcon = (ImageView) senderRow.findViewById(R.id.widget_itbr_icon);
            TextView senderText = (TextView) senderRow.findViewById(R.id.widget_itbr_text);
            senderRow.findViewById(R.id.widget_itbr_button).setVisibility(View.GONE);
            senderIcon.setImageResource(R.drawable.cloud_googblue);
            senderIcon.setPadding(0, 0, (int) (8 * density), 0);
            senderText.setText(getString(R.string.groups_sender_id, sender.senderId));
            sendersList.addView(senderRow);
            for (DeviceGroup deviceGroup : sender.groups.values()) {
                LinearLayout row = (LinearLayout) getActivity().getLayoutInflater()
                        .inflate(R.layout.widget_icon_text_button_row, sendersList, false);
                ImageView icon = (ImageView) row.findViewById(R.id.widget_itbr_icon);
                TextView label = (TextView) row.findViewById(R.id.widget_itbr_text);
                Button button = (Button) row.findViewById(R.id.widget_itbr_button);
                icon.setImageResource(R.drawable.group_grey600);
                label.setText(deviceGroup.notificationKeyName);
                label.setBackgroundResource(selectableBackgroundResource);
                label.setTag(R.id.tag_action, ACTION_OPEN_GROUP);
                label.setTag(R.id.tag_senderid, sender.senderId);
                label.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                label.setOnClickListener(this);

                button.setText(R.string.groups_delete);
                button.setTag(R.id.tag_action, ACTION_DELETE_GROUP);
                button.setTag(R.id.tag_senderid, sender.senderId);
                button.setTag(R.id.tag_group, deviceGroup.notificationKeyName);
                button.setOnClickListener(this);
                row.setPadding((int) (16 * density), 0, 0, 0);
                sendersList.addView(row);
            }//  w  ww.  j  ava  2 s.  c o m
        }
    }
    if (sendersList.getChildCount() == 0) {
        TextView noTokens = new TextView(getActivity());
        noTokens.setText(getString(R.string.groups_no_groups_available));
        noTokens.setTypeface(null, Typeface.ITALIC);
        sendersList.addView(noTokens);
    }
    FrameLayout topicsView = (FrameLayout) getActivity().findViewById(R.id.groups_list_wrapper);
    topicsView.removeAllViews();
    topicsView.addView(sendersList);
}

From source file:com.chenjishi.u148.view.TabPageIndicator.java

public void setTheme(int theme) {
    final boolean isNight = theme == Constants.MODE_NIGHT;
    setBackgroundColor(isNight ? 0xFF1C1C1C : 0xFFE5E5E5);

    final int tabCount = mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        final TextView child = (TextView) mTabLayout.getChildAt(i);
        child.setTextColor(getResources()
                .getColorStateList(isNight ? R.color.tab_text_color_night : R.color.tab_text_color));
        child.setBackgroundResource(
                isNight ? R.drawable.tab_indicator_night : R.drawable.abs__tab_indicator_ab_holo);
    }/*  w  w w. ja  v a2 s .  c  om*/
}

From source file:org.telegram.ui.Components.BotKeyboardView.java

public void setButtons(TLRPC.TL_replyKeyboardMarkup buttons) {
    botButtons = buttons;//from   w  w w . ja  v a 2 s . co m
    container.removeAllViews();
    buttonViews.clear();

    if (buttons != null && botButtons.rows.size() != 0) {
        isFullSize = !buttons.resize;
        buttonHeight = !isFullSize ? 42
                : (int) Math.max(42,
                        (panelHeight - AndroidUtilities.dp(30)
                                - (botButtons.rows.size() - 1) * AndroidUtilities.dp(10))
                                / botButtons.rows.size() / AndroidUtilities.density);
        for (int a = 0; a < buttons.rows.size(); a++) {
            TLRPC.TL_keyboardButtonRow row = buttons.rows.get(a);

            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.HORIZONTAL);
            container.addView(layout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, buttonHeight, 15,
                    a == 0 ? 15 : 10, 15, a == buttons.rows.size() - 1 ? 15 : 0));

            float weight = 1.0f / row.buttons.size();
            for (int b = 0; b < row.buttons.size(); b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                TextView textView = new TextView(getContext());
                textView.setTag(button);
                textView.setTextColor(ContextCompat.getColor(getContext(), R.color.bot_keyboard_text));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                textView.setGravity(Gravity.CENTER);
                textView.setBackgroundResource(R.drawable.bot_keyboard_button2);
                textView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                textView.setText(Emoji.replaceEmoji(button.text, textView.getPaint().getFontMetricsInt(),
                        AndroidUtilities.dp(16), false));
                layout.addView(textView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, weight, 0, 0,
                        b != row.buttons.size() - 1 ? 10 : 0, 0));
                textView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        delegate.didPressedButton((TLRPC.KeyboardButton) v.getTag());
                    }
                });
                buttonViews.add(textView);
            }
        }
    }
}

From source file:com.baoyz.bigbang.BigBangLayout.java

public void addTextItem(String text) {
    TextView view = new TextView(getContext());
    view.setText(text);//from  www  .  j a  va2s.  c o  m
    view.setBackgroundResource(R.drawable.item_background);
    view.setTextColor(ContextCompat.getColorStateList(getContext(), R.color.bigbang_item_text));
    view.setGravity(Gravity.CENTER);
    addView(view);
}

From source file:com.google.android.apps.flexbox.MainActivity.java

private TextView createBaseFlexItemTextView(int index) {
    TextView textView = new TextView(this);
    textView.setBackgroundResource(R.drawable.flex_item_background);
    textView.setText(String.valueOf(index + 1));
    textView.setGravity(Gravity.CENTER);
    return textView;
}

From source file:com.weekcalendar.WeekFragment.java

private void setSelectedDateBackground(TextView selectedDateTv) {
    if (mSelectorDateIndicatorValue != 0) {
        for (TextView tv : mTextViewArray) {
            tv.setBackgroundColor(Color.TRANSPARENT);
        }/*from  w  w w.ja  va2s.co  m*/
        selectedDateTv.setBackgroundResource(mSelectorDateIndicatorValue);
    }

    if (mSelectorHighlightColor != -1) {
        for (TextView tv : mTextViewArray) {
            tv.setTextColor(mPrimaryTextColor);
        }
        if (mCurrentDateIndex > -1) {
            mTextViewArray[mCurrentDateIndex].setTextColor(mCurrentDateIndicatorValue);
        }
        selectedDateTv.setTextColor(mSelectorHighlightColor);
    }
}