Example usage for android.widget TextView setBackgroundColor

List of usage examples for android.widget TextView setBackgroundColor

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout make_Active_Tab(String text, Drawable dr) {

    LinearLayout ll = new LinearLayout(this);
    ll.setPadding(0, 0, 2, 1);//w  ww  .j  a v a  2  s.  co m
    ll.setBackgroundColor(Color.GRAY);

    ll.setTag("ll");
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setLayoutParams(
            new LinearLayout.LayoutParams(0, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, 1));

    //------ Text 
    TextView tv = new TextView(this);
    tv.setBackgroundColor(Color.TRANSPARENT);
    tv.setTag("tv");
    ll.addView(tv);

    // ------ hbar
    View hbar = new View(this);
    hbar.setTag("hbar");
    hbar.setLayoutParams(
            new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.FILL_PARENT, 10));

    ll.addView(hbar);

    ////////////////////////////////////////
    return ActivateColorize(ll, text, dr);
}

From source file:org.odk.collect.android.activities.AppListActivity.java

private void setupDrawerItems() {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            sortingOptions) {//from  ww w .  ja va  2  s  .c o m
        @NonNull
        @Override
        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
            TextView textView = (TextView) super.getView(position, convertView, parent);
            if (position == getSelectedSortingOrder()) {
                textView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.light_blue));
            }
            textView.setPadding(50, 0, 0, 0);
            return textView;
        }
    };
    drawerList.setAdapter(adapter);
    drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            parent.getChildAt(selectedSortingOrder).setBackgroundColor(Color.TRANSPARENT);
            view.setBackgroundColor(ContextCompat.getColor(getBaseContext(), R.color.light_blue));
            performSelectedSearch(position);
            drawerLayout.closeDrawer(Gravity.END);
        }
    });
}

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout make_Inactive_Tab(String text, Drawable dr) {

    LinearLayout ll = new LinearLayout(this);

    ll.setPadding(0, 0, 2, 1);/*from   ww  w.j  a  v a 2  s.  c  o  m*/

    ll.setBackgroundColor(Color.GRAY);

    ll.setTag("ll");
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setLayoutParams(
            new LinearLayout.LayoutParams(0, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, 1));

    //------ Text 
    TextView tv = new TextView(this);
    tv.setBackgroundColor(Color.TRANSPARENT);
    tv.setTag("tv");
    ll.addView(tv);

    // ------ hbar
    View hbar = new View(this);
    hbar.setTag("hbar");
    hbar.setLayoutParams(
            new LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.FILL_PARENT, 10));

    ll.addView(hbar);

    /////////////////////////////////////
    return InActivateColorize(ll, text, dr);
}

From source file:gov.wa.wsdot.android.wsdot.ui.tollrates.I405TollRatesFragment.java

/**
 * Adds a toll rate accuracy disclaimer to the bottom of the view
 * @param root/*  w ww  .  j  av a  2  s  .c o m*/
 */
private void addDisclaimerView(ViewGroup root) {
    FrameLayout frame = root.findViewById(R.id.list_container);
    TextView textView = new TextView(getContext());
    textView.setBackgroundColor(getResources().getColor(R.color.alerts));
    textView.setText(
            "Estimated toll rates provided as a courtesy. Youll always pay the toll you see on actual road signs when you enter.");
    textView.setPadding(15, 20, 15, 15);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM;
    textView.setLayoutParams(params);
    frame.addView(textView);
}

From source file:net.mm2d.dmsexplorer.CdsDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.frg_cds_detail, container, false);

    final String udn = getArguments().getString(Const.EXTRA_UDN);
    final MediaServer server = DataHolder.getInstance().getMsControlPoint().getMediaServer(udn);
    final CdsObject object = getArguments().getParcelable(Const.EXTRA_OBJECT);
    if (object == null || server == null) {
        getActivity().finish();//w  w w.j  ava 2s.com
        return rootView;
    }

    final TextView titleView = (TextView) rootView.findViewById(R.id.title);
    if (titleView != null) {
        final String title = object.getTitle();
        titleView.setText(AribUtils.toDisplayableString(title));
        titleView.setBackgroundColor(ThemeUtils.getAccentColor(title));
    }

    final RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.cds_detail);
    final PropertyAdapter adapter = new PropertyAdapter(getContext());
    adapter.setOnItemLinkClickListener(this);
    setupPropertyAdapter(getActivity(), adapter, object);
    recyclerView.setAdapter(adapter);

    setupFloatingActionButton(rootView, object);
    return rootView;
}

From source file:com.timothy.android.api.fragment.PageFragment.java

public void setAllComponent(List<HtmlCleanAPI.HtmlContent> hcList) {
    Log.i(LOG_TAG, "setAllComponent()...");
    for (HtmlCleanAPI.HtmlContent hc : hcList) {
        String tag = hc.getTag();
        String content = hc.getContent();
        String contentRBlank = StringUtil.rmvEnter(StringUtil.trim(StringUtil.mergeBlank(content)));
        String contentRSpecial = StringUtil.rmvSpecial(contentRBlank);

        if (StringUtil.isEmpty(content) || StringUtil.isEmpty(contentRBlank)
                || StringUtil.isEmpty(contentRSpecial)) {
            continue;
        }//from  w  w  w . j a  v  a 2s  .com

        Log.i(LOG_TAG, "tag:" + tag);
        Log.i(LOG_TAG, "content:" + content);

        if (tag.equalsIgnoreCase("P")) {
            final TextView tagPTV = new TextView(mContext);
            tagPTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagPTV.setLayoutParams(lp);
            tagPTV.setPadding(3, 3, 3, 3);
            tagPTV.setPaddingRelative(3, 3, 3, 3);
            tagPTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagPTV.setTextColor(Color.BLACK);
            tagPTV.setText(contentRSpecial);
            tagPTV.setTextSize(TEXT_SIZE);
            tagPTV.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagPTV.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagPTV);

        } else if (tag.equalsIgnoreCase("pre")) {
            final TextView tagPre = new TextView(mContext);
            tagPre.setBackgroundColor(Color.parseColor("#D2EADE"));
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagPre.setLayoutParams(lp);
            tagPre.setPadding(2, 2, 2, 2);
            tagPre.setPaddingRelative(2, 2, 2, 2);
            tagPre.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagPre.setTextColor(Color.BLACK);
            //            String contentRSpecial = StringUtil.rmvSpecial(content);
            tagPre.setText(StringUtil.rmvSpecial(content));
            tagPre.setTextSize(TEXT_SIZE);
            tagPre.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagPre.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagPre);
        } else if (tag.equalsIgnoreCase("dt") || tag.equalsIgnoreCase("H1") || tag.equalsIgnoreCase("H2")
                || tag.equalsIgnoreCase("H3")) {//title
            TextView tagDtHTV = new TextView(mContext);
            tagDtHTV.setBackgroundColor(Color.DKGRAY);
            tagDtHTV.setTypeface(null, Typeface.BOLD);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 0, 2, 0);
            tagDtHTV.setLayoutParams(lp);
            tagDtHTV.setPadding(2, 2, 2, 2);
            tagDtHTV.setPaddingRelative(2, 2, 2, 2);
            tagDtHTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagDtHTV.setTextColor(Color.WHITE);
            tagDtHTV.setText(contentRSpecial);
            tagDtHTV.setTextSize(TEXT_SIZE);
            lineLayout.addView(tagDtHTV);
        } else if (tag.equalsIgnoreCase("dd")) {
            final TextView tagDD = new TextView(mContext);
            tagDD.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagDD.setLayoutParams(lp);
            tagDD.setPadding(3, 3, 3, 3);
            tagDD.setPaddingRelative(3, 3, 3, 3);
            tagDD.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagDD.setTextColor(Color.BLACK);
            tagDD.setText(contentRSpecial);
            tagDD.setTextSize(TEXT_SIZE);
            tagDD.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagDD.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagDD);
        } else if (tag.equalsIgnoreCase("li")) {
            final TextView tagLigTV = new TextView(mContext);
            tagLigTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            tagLigTV.setLayoutParams(lp);
            tagLigTV.setPaddingRelative(2, 2, 2, 2);
            tagLigTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            tagLigTV.setTextColor(Color.BLACK);
            tagLigTV.setText(contentRSpecial);
            tagLigTV.setTextSize(TEXT_SIZE);
            tagLigTV.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    openDialog(tagLigTV.getText().toString());
                    return false;
                }
            });
            lineLayout.addView(tagLigTV);
        } else if (tag.equalsIgnoreCase("img")) {
            final TextView imgTV = new TextView(mContext);
            imgTV.setBackgroundResource(R.drawable.tag_p_drawable);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                    LayoutParams.WRAP_CONTENT);
            lp.setMargins(2, 2, 2, 2);
            imgTV.setLayoutParams(lp);
            imgTV.setPaddingRelative(2, 2, 2, 2);
            imgTV.setMovementMethod(ScrollingMovementMethod.getInstance());
            imgTV.setTextColor(Color.BLACK);
            imgTV.setText(content);
            imgTV.setTextSize(TEXT_SIZE);
            imgTV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    TextView tv = (TextView) v;
                    String path = tv.getText().toString();
                    if (path != null && path.trim().length() > 0) {
                        openDialog2(path);
                    }
                }
            });
            lineLayout.addView(imgTV);
        }
    }
}

From source file:org.cvasilak.jboss.mobile.app.fragments.ProfileViewFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // adjust the title
    ActionBar bar = ((ActionBarActivity) getActivity()).getSupportActionBar();

    if (path == null)
        bar.setTitle(application.getOperationsManager().getServer().getName());
    else//w w w  .j a v  a 2s . co m
        bar.setTitle(path.get(path.size() - 1));

    MergeAdapter adapter = new MergeAdapter();

    TextView sectionHeader;

    // Section: Attributes
    sectionHeader = new TextView(getActivity());
    sectionHeader.setBackgroundColor(Color.DKGRAY);
    sectionHeader.setPadding(15, 10, 0, 10);
    sectionHeader.setText(R.string.attributes);
    adapter.addView(sectionHeader);

    adapter.addAdapter(new AttributeAdapter(attributes));

    // Section ChildTypes
    sectionHeader = new TextView(getActivity());
    sectionHeader.setBackgroundColor(Color.DKGRAY);
    sectionHeader.setPadding(15, 10, 0, 10);
    sectionHeader.setText(R.string.child_types);
    adapter.addView(sectionHeader);

    adapter.addAdapter(new ChildTypeAdapter(childTypes));

    // Section Operations
    sectionHeader = new TextView(getActivity());
    sectionHeader.setBackgroundColor(Color.DKGRAY);
    sectionHeader.setHeight(20);
    sectionHeader.setPadding(15, 10, 0, 10);
    adapter.addView(sectionHeader);

    adapter.addAdapter(new IconTextRowAdapter(getActivity(), Arrays.asList(getString(R.string.operations)),
            R.drawable.ic_operations));

    setListAdapter(adapter);
}

From source file:fr.cph.chicago.core.activity.TrainMapActivity.java

private void drawTrains(@NonNull final List<Train> trains) {
    mapFragment.getMapAsync(googleMap -> {
        // TODO see if views can actually be null.
        if (views == null) {
            views = new HashMap<>();
        } else {//from   ww  w .j  a  v a 2 s .c  o  m
            views.clear();
        }
        Stream.of(markers).forEach(Marker::remove);
        markers.clear();
        final BitmapDescriptor bitmapDescr = trainListener.getCurrentBitmapDescriptor();
        Stream.of(trains).forEach(train -> {
            final LatLng point = new LatLng(train.getPosition().getLatitude(),
                    train.getPosition().getLongitude());
            final String title = "To " + train.getDestName();
            final String snippet = Integer.toString(train.getRouteNumber());

            final Marker marker = googleMap
                    .addMarker(new MarkerOptions().position(point).title(title).snippet(snippet)
                            .icon(bitmapDescr).anchor(0.5f, 0.5f).rotation(train.getHeading()).flat(true));
            markers.add(marker);

            final View view = getLayoutInflater().inflate(R.layout.marker_train, viewGroup, false);
            final TextView title2 = (TextView) view.findViewById(R.id.title);
            title2.setText(title);

            final TextView color = (TextView) view.findViewById(R.id.route_color_value);
            color.setBackgroundColor(TrainLine.fromXmlString(line).getColor());

            views.put(marker, view);
        });
        trainListener.setTrainMarkers(markers);

        googleMap.setOnCameraChangeListener(trainListener);
    });
}

From source file:utils.widget.vpi_lib.TabPageIndicator_Custom.java

@Override
public void setCurrentItem(final int item) {

    // final RippleView rippleView = (RippleView) mTabLayout
    // .findViewById(R.id.ripTabItem);
    // rippleView.setRippleColor(R.color.rippelColorOrange);
    // rippleView
    // .setOnRippleCompleteListener(new
    // RippleView.OnRippleCompleteListener() {
    ///* ww  w  .  j  a  v  a  2  s. c  o  m*/
    // @Override
    // public void onComplete(RippleView rippleView) {
    if (mViewPager == null) {
        throw new IllegalStateException("ViewPager has not been bound.");
    }
    mSelectedTabIndex = item;
    mViewPager.setCurrentItem(item);

    final int tabCount = mTabLayout.getChildCount();
    for (int i = 0; i < tabCount; i++) {
        final View child = mTabLayout.getChildAt(i);
        final boolean isSelected = (i == item);
        child.setSelected(isSelected);

        // TODO - Trigger (Arrow) Setting
        // Toast.makeText(getContext(),
        // "Selected ID :"+item,
        // Toast.LENGTH_SHORT).show();
        // ImageView img = (ImageView)
        // child.findViewById(R.id.img_trigger);
        TextView txtTitle = (TextView) child.findViewById(R.id.vpi_custom_txt_Title);
        TextView txtBottom = (TextView) child.findViewById(R.id.vpi_custom_txt_btm);

        if (isSelected) {
            animateToTab(item);
            txtBottom.setBackgroundColor(getResources().getColor(R.color.vpi_focus));
            txtBottom.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 8));
            txtTitle.setTextColor(getResources().getColor(R.color.vpi_focus));
            txtTitle.setTypeface(null, Typeface.BOLD);
            // img.setVisibility(View.VISIBLE);
        } else {
            txtBottom.setBackgroundColor(getResources().getColor(R.color.vpi_non_focus));
            txtBottom.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
            txtTitle.setTextColor(getResources().getColor(R.color.vpi_non_focus));
            txtTitle.setTypeface(null, Typeface.NORMAL);
            // img.setVisibility(View.INVISIBLE);
        }
    }
    // }
    //
    // });

}

From source file:com.geoffreybuttercrumbs.arewethereyet.ZonePicker.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    int received_Set_Ringtone = 131072;
    int set_Pinned = 1;
    if (requestCode == received_Set_Ringtone && resultCode == RESULT_OK) {
        uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
        if (uri != null) {
            Toast.makeText(this, "Setting ringtone", Toast.LENGTH_LONG).show();
        } else/*w  w  w .  ja  v a 2  s  .  co m*/
            Toast.makeText(this, "Ringtone: Silent", Toast.LENGTH_LONG).show();
    } else if (requestCode == 10001) {
        TextView donateView = (TextView) mFrag.getView().findViewById(R.id.row_title_donate);
        if (donateView != null) {
            donateView.setText("Thanks!");
            donateView.setBackgroundColor(0xFF11FF11);
        }
    } else if (requestCode == set_Pinned && resultCode == RESULT_OK) {
        if (data.getExtras() != null) {
            setNewAlarmZone(data.getExtras());
        }
    }
}