Example usage for android.widget TextView setTextColor

List of usage examples for android.widget TextView setTextColor

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setTextColor(ColorStateList colors) 

Source Link

Document

Sets the text color.

Usage

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

private TextView getPanel(String desc, LayoutParams params, int textColor) {
    desc = desc.trim().toUpperCase();//from   w  ww.  ja  v  a 2 s .  co m
    final TextView panelUi = new TextView(getSherlockActivity());

    panelUi.setGravity(Gravity.CENTER_HORIZONTAL);
    panelUi.setLayoutParams(params);
    panelUi.setTextColor(textColor);

    String prefix = (String) desc.subSequence(0, 2);
    prefix = prefix.trim();
    try {
        // Start with a figure: authorized duration
        Integer.valueOf(prefix.trim());
        panelUi.setBackgroundResource(R.drawable.bg_panel_parking);
    } catch (NumberFormatException e) {
        if (desc.subSequence(0, 1).equals("P")) {
            // Starts with "P " (trimmed): authorized
            panelUi.setBackgroundResource(R.drawable.bg_panel_parking);
            desc = desc.substring(1);
        } else if (desc.subSequence(0, 2).equals("\\A")) {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_stopping);
            desc = desc.substring(2);
        } else if (desc.subSequence(0, 2).equals("\\P")) {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_parking);
            desc = desc.substring(2);
        } else {
            panelUi.setBackgroundResource(R.drawable.bg_panel_no_parking);
        }
    }

    panelUi.setText(desc.trim());

    return panelUi;
}

From source file:com.android.app.buystoreapp.PagerSlidingTabStrip.java

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));
                }// ww w. j av a  2  s  .  c  o m
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, selectedTabTextSize);
            }
        }
    }

}

From source file:com.adkdevelopment.earthquakesurvival.ui.PagerActivity.java

/**
 * Method to set tab images and highlights on tab switching
 *///from  w  ww . j a va2  s.com
private void setTabImages() {
    if (mTab != null) {

        int[] iconSet = { R.drawable.error_grey, R.drawable.map_grey, R.drawable.newspaper_grey,
                R.drawable.lightbulb_grey, R.drawable.error_blue, R.drawable.map_blue,
                R.drawable.newspaper_blue, R.drawable.lightbulb_blue };

        // Set custom layouts for each Tab
        for (int i = 0, n = mTab.getTabCount(); i < n; i++) {
            TabLayout.Tab tabLayout = mTab.getTabAt(i);

            if (tabLayout != null) {
                tabLayout.setCustomView(R.layout.pager_tab_layout);
                View customView = tabLayout.getCustomView();

                if (customView != null) {
                    ImageView imageView = ButterKnife.findById(customView, R.id.tab_item_image);
                    TextView textView = ButterKnife.findById(customView, R.id.tab_item_text);
                    textView.setText(tabLayout.getText());

                    if (i == 0) {
                        textView.setTextColor(mColorSelected);
                        imageView.setImageResource(iconSet[i + iconSet.length / 2]);
                    } else {
                        textView.setTextColor(mColorUnselected);
                        imageView.setImageResource(iconSet[i]);
                    }
                }
            }
        }

        // Highlight image and text on selection
        mTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                setTitle();
                View customView = tab.getCustomView();
                if (customView != null) {
                    ImageView imageView = ButterKnife.findById(customView, R.id.tab_item_image);
                    imageView.setImageResource(iconSet[tab.getPosition() + iconSet.length / 2]);

                    TextView textView = ButterKnife.findById(customView, R.id.tab_item_text);
                    textView.setTextColor(mColorSelected);
                }
                mViewPager.setCurrentItem(tab.getPosition());

                Fragment fragment = mPagerAdapter.getRegisteredFragment(tab.getPosition());
                if (fragment instanceof SurvivalFragment) {
                    ((SurvivalFragment) fragment).animateViewsIn();
                } else if (fragment instanceof NewsFragment) {
                    ((NewsFragment) fragment).animateViewsIn();
                } else if (fragment instanceof RecentFragment) {
                    ((RecentFragment) fragment).animateViewsIn();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                View customView = tab.getCustomView();
                if (customView != null) {
                    ImageView imageView = ButterKnife.findById(customView, R.id.tab_item_image);
                    imageView.setImageResource(iconSet[tab.getPosition()]);

                    TextView textView = ButterKnife.findById(customView, R.id.tab_item_text);
                    textView.setTextColor(mColorUnselected);
                }
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                Fragment fragment = mPagerAdapter.getRegisteredFragment(tab.getPosition());

                if (fragment instanceof RecentFragment) {
                    ((RecentFragment) fragment).scrollToTop();
                } else if (fragment instanceof NewsFragment) {
                    ((NewsFragment) fragment).scrollToTop();
                }
            }
        });

    }
}

From source file:com.astuetz.PagerSlidingTabStripExtend.java

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));
                }/*  w  ww. j ava2 s.c  om*/
            }

            //??
            if (i == mSelectedIndex) {
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabSelectedTextSize);
                tab.setTextColor(tabSelectedTextColor);
            }
        }
    }

}

From source file:app.views.PagerSlidingTabStrip.java

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));
                }//from   ww  w . j  ava 2  s . c o  m
            }
            if (i == selectedPosition) {
                tab.setTextColor(selectedTabTextColor);
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, selectedTabTextSize);
            }
        }
    }

}

From source file:com.astuetz.PagerSlidingTabStripCopy.java

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));
                }//from   w w w  . j a va2s.c  om

            }
            if (mCurrent == i) {
                tab.setTextSize(mTitleSelectedSize);
                tab.setTypeface(tabTypeface, tabTypefaceStyle);
                tab.setTextColor(mTitleSelectedColor);
            }
        }
    }

}

From source file:com.astuetz.PagerSlidingTabStripExpand.java

/**
 *  ?//w ww. j  a v a2  s .  c o  m
 */
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 (mCurrentSelectedIndex == i) {
                tab.setTextColor(tabSelectedTextColor);
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabSelectedTextSize);
            }
        }
    }

}

From source file:com.njlabs.amrita.aid.aums.AumsActivity.java

private void loadCgpa() {
    final TextView cgpaView = (TextView) findViewById(R.id.student_cgpa);
    aums.getCGPA(new TextResponse() {
        @Override/*from   w  w w. j  a v  a 2s  . com*/
        public void onSuccess(String cgpa) {
            cgpaView.setText(cgpa);
        }

        @Override
        public void onFailure(Throwable throwable) {
            cgpaView.setText("error");
            cgpaView.setTextColor(getResources().getColor(R.color.md_red_400));
            Ln.e(throwable);
        }

    });
}

From source file:net.mypapit.mobile.myrepeater.DisplayMap.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_map);
    overridePendingTransition(R.anim.activity_open_translate, R.anim.activity_close_scale);

    hashMap = new HashMap<Marker, MapInfoObject>();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }//from  ww  w  .j a va2 s . c  o m

    map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    if (map == null) {

        // Log.e("Map NULL", "MAP NULL");
        Toast.makeText(this, "Unable to display Map", Toast.LENGTH_SHORT).show();

    } else {

        LatLng latlng = (LatLng) getIntent().getExtras().get("LatLong");

        Repeater xlocation = new Repeater("", new Double[] { latlng.latitude, latlng.longitude });

        rl = RepeaterListActivity.loadData(R.raw.repeaterdata5, this);
        xlocation.calcDistanceAll(rl);
        rl.sort();

        map.setMyLocationEnabled(true);
        map.setOnInfoWindowClickListener(this);
        map.getUiSettings().setZoomControlsEnabled(true);

        AdView mAdView = (AdView) findViewById(R.id.adViewMap);
        mAdView.loadAd(new AdRequest.Builder().build());

        // counter i, for mapping marker with integer
        int i = 0;

        for (Repeater repeater : rl) {

            MarkerOptions marking = new MarkerOptions();
            marking.position(new LatLng(repeater.getLatitude(), repeater.getLongitude()));
            marking.title(repeater.getCallsign() + " - " + repeater.getDownlink() + "MHz (" + repeater.getClub()
                    + ")");

            marking.snippet("Tone: " + repeater.getTone() + " Shift: " + repeater.getShift());

            RepeaterMapInfo rmi = new RepeaterMapInfo(repeater);
            rmi.setIndex(i);

            hashMap.put(map.addMarker(marking), rmi);

            i++;

        }

        // Marker RKG = map.addMarker(new MarkerOptions().position(new
        // LatLng(6.1,100.3)).title("9M4RKG"));

        map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 10));
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

        cache = this.getSharedPreferences(CACHE_PREFS, 0);

        Date cachedate = new Date(cache.getLong(CACHE_TIME, new Date(20000).getTime()));

        long secs = (new Date().getTime() - cachedate.getTime()) / 1000;
        long hours = secs / 3600L;
        secs = secs % 3600L;
        long mins = secs / 60L;

        if (mins < 5) {
            String jsoncache = cache.getString(CACHE_JSON, "none");
            if (jsoncache.compareToIgnoreCase("none") == 0) {
                new GetUserInfo(latlng, this).execute();

            } else {

                loadfromCache(jsoncache);
                // Toast.makeText(this, "Loaded from cache: " + mins +
                // " mins", Toast.LENGTH_SHORT).show();
            }

        } else {

            new GetUserInfo(latlng, this).execute();

        }

        map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

            @Override
            public View getInfoWindow(Marker marker) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public View getInfoContents(Marker marker) {
                Context context = getApplicationContext(); // or
                // getActivity(),
                // YourActivity.this,
                // etc.

                LinearLayout info = new LinearLayout(context);
                info.setOrientation(LinearLayout.VERTICAL);

                TextView title = new TextView(context);
                title.setTextColor(Color.BLACK);
                title.setGravity(Gravity.CENTER);
                title.setTypeface(null, Typeface.BOLD);
                title.setText(marker.getTitle());

                TextView snippet = new TextView(context);
                snippet.setTextColor(Color.GRAY);
                snippet.setText(marker.getSnippet());

                info.addView(title);
                info.addView(snippet);

                return info;
            }
        });

    }

}

From source file:cn.com.incito.driver.UI.detailDialog.PagerSlidingTabStrip.java

private void updateTabStyles() {

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

        View v = tabsContainer.getChildAt(i);

        v.setLayoutParams(defaultTabLayoutParams);
        v.setBackgroundResource(tabBackgroundResId);
        if (shouldExpand) {
            v.setPadding(0, 0, 0, 0);/* ww  w  .j  a  v  a  2  s .  com*/
        } 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().toString().toUpperCase(locale));
                }
            }
        }
    }

}