List of usage examples for android.widget TextView getTextColors
public final ColorStateList getTextColors()
From source file:com.finchuk.clock2.alarms.ui.BaseAlarmViewHolder.java
private void bindTime(Alarm alarm) { String time = DateFormat.getTimeFormat(getContext()).format(new Date(alarm.ringsAt())); if (DateFormat.is24HourFormat(getContext())) { mTime.setText(time);//from w w w.j a v a 2s.c o m } else { TimeTextUtils.setText(time, mTime); } // Use a mock TextView to get our colors, because its ColorStateList is never // mutated for the lifetime of this ViewHolder (even when reused). // This solution is robust against dark/light theme changes, whereas using // color resources is not. TextView colorsSource = (TextView) itemView.findViewById(R.id.colors_source); ColorStateList colors = colorsSource.getTextColors(); int def = colors.getDefaultColor(); // Too light // int disabled = colors.getColorForState(new int[] {-android.R.attr.state_enabled}, def); // Material guidelines say text hints and disabled text should have the same color. int disabled = colorsSource.getCurrentHintTextColor(); // However, digging around in the system's textColorHint for 21+ says its 50% black for our // light theme. I'd like to follow what the guidelines says, but I want code that is robust // against theme changes. Alternatively, override the attribute values to what you want // in both your dark and light themes... // int disabled = ContextCompat.getColor(getContext(), R.color.text_color_disabled_light); // We only have two states, so we don't care about losing the other state colors. mTime.setTextColor(alarm.isEnabled() ? def : disabled); }
From source file:org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter.java
@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { View view = mInflater.inflate(R.layout.view_key_adv_subkey_item, null); if (mDefaultTextColor == null) { TextView keyId = (TextView) view.findViewById(R.id.subkey_item_key_id); mDefaultTextColor = keyId.getTextColors(); }/*www. j a v a 2s . c o m*/ return view; }
From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java
private boolean recurseGroup(Context context, ViewGroup gp) { final int count = gp.getChildCount(); for (int i = 0; i < count; ++i) { if (gp.getChildAt(i) instanceof TextView) { final TextView text = (TextView) gp.getChildAt(i); final String szText = text.getText().toString(); if (COLOR_SEARCH_RECURSE_TIP.equals(szText)) { notification_text_color = text.getTextColors().getDefaultColor(); notification_text_size = text.getTextSize(); DisplayMetrics metrics = new DisplayMetrics(); WindowManager systemWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); systemWM.getDefaultDisplay().getMetrics(metrics); notification_text_size /= metrics.scaledDensity; return true; }/*from w ww .java 2 s .c o m*/ } else if (gp.getChildAt(i) instanceof ViewGroup) return recurseGroup((Context) context, (ViewGroup) gp.getChildAt(i)); } return false; }
From source file:net.alexjf.tmm.fragments.ImmedTransactionDetailsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_immedtransaction_details, container, false); detailsListView = (ListView) v.findViewById(android.R.id.list); adapter = new TwoLineTextAdapter<TransactionDetails>(getActivity()) { public void setTitleText(TextView titleTextView, TransactionDetails item) { titleTextView.setText(item.label); }//w ww . j ava2 s . c o m public void setValueText(TextView valueTextView, TransactionDetails item) { valueTextView.setText(item.value); valueTextView.setCompoundDrawablesWithIntrinsicBounds(item.leftDrawableId, 0, 0, 0); if (item.valueColor == null) { valueTextView.setTextColor(valueTextView.getTextColors().getDefaultColor()); } else { valueTextView.setTextColor(item.valueColor); } } ; }; detailsListView.setAdapter(adapter); return v; }
From source file:org.openhab.habdroid.ui.OpenHABWidgetArrayAdapter.java
private TextView getValueTextView(RelativeLayout widgetView, OpenHABWidget openHABWidget) { // Get TextView for widget value and set it's color Integer valueColor = openHABWidget.getValueColor(); TextView valueTextView = (TextView) widgetView.findViewById(R.id.widgetvalue); if (valueColor != null && valueTextView != null) { Log.d(HABApplication.getLogTag(), String.format("Setting value color to %d", valueColor)); valueTextView.setTextColor(valueColor); } else if (valueTextView != null) { TextView defaultTextView = new TextView(widgetView.getContext()); valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); }/*from w w w . ja v a 2 s . co m*/ return valueTextView; }
From source file:org.openhab.habdroid.ui.OpenHABWidgetArrayAdapter.java
private TextView getLabelTextView(RelativeLayout widgetView, OpenHABWidget openHABWidget) { // Get TextView for widget label and set it's color Integer labelColor = openHABWidget.getLabelColor(); TextView labelTextView = (TextView) widgetView.findViewById(R.id.widgetlabel); if (labelColor != null && labelTextView != null) { Log.d(HABApplication.getLogTag(), String.format("Setting label color to %d", labelColor)); labelTextView.setTextColor(labelColor); } else if (labelTextView != null) { TextView defaultTextView = new TextView(widgetView.getContext()); labelTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); }/* w w w . ja v a 2 s. co m*/ return labelTextView; }
From source file:org.da_cha.android.bluegnss.MainActivity.java
private void displayAboutDialog() { View messageView = getLayoutInflater().inflate(R.layout.about, null, false); // we need this to enable html links TextView textView = (TextView) messageView.findViewById(R.id.about_license); textView.setMovementMethod(LinkMovementMethod.getInstance()); // When linking text, force to always use default color. This works // around a pressed color state bug. int defaultColor = textView.getTextColors().getDefaultColor(); textView.setTextColor(defaultColor); textView = (TextView) messageView.findViewById(R.id.about_sources); textView.setTextColor(defaultColor); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.about_title); builder.setIcon(R.drawable.gplv3_icon); builder.setView(messageView);//from w ww . j a v a2 s . c o m builder.show(); }
From source file:com.app.blockydemo.content.bricks.SetVariableBrick.java
@Override public View getViewWithAlpha(int alphaValue) { if (view != null) { TextView textSetVariable = (TextView) view.findViewById(R.id.brick_set_variable_label); TextView textTo = (TextView) view.findViewById(R.id.brick_set_variable_to_textview); TextView editVariable = (TextView) view.findViewById(R.id.brick_set_variable_edit_text); Spinner variablebrickSpinner = (Spinner) view.findViewById(R.id.set_variable_spinner); ColorStateList color = textSetVariable.getTextColors().withAlpha(alphaValue); variablebrickSpinner.getBackground().setAlpha(alphaValue); if (adapterView != null) { ((TextView) adapterView.getChildAt(0)).setTextColor(color); }// w w w. j av a2 s. c o m textSetVariable.setTextColor(textSetVariable.getTextColors().withAlpha(alphaValue)); textTo.setTextColor(textTo.getTextColors().withAlpha(alphaValue)); editVariable.setTextColor(editVariable.getTextColors().withAlpha(alphaValue)); editVariable.getBackground().setAlpha(alphaValue); this.alphaValue = (alphaValue); } return view; }
From source file:com.csipsimple.service.SipNotifications.java
private boolean recurseSearchNotificationPrimaryText(ViewGroup gp) { final int count = gp.getChildCount(); for (int i = 0; i < count; ++i) { if (gp.getChildAt(i) instanceof TextView) { final TextView text = (TextView) gp.getChildAt(i); final String szText = text.getText().toString(); if (TO_SEARCH.equals(szText)) { notificationPrimaryTextColor = text.getTextColors().getDefaultColor(); return true; }//from www .jav a 2 s.c o m } else if (gp.getChildAt(i) instanceof ViewGroup) { if (recurseSearchNotificationPrimaryText((ViewGroup) gp.getChildAt(i))) { return true; } } } return false; }
From source file:com.app.blockydemo.content.bricks.ChangeVariableBrick.java
@Override public View getViewWithAlpha(int alphaValue) { if (view != null) { View layout = view.findViewById(R.id.brick_change_variable_layout); Drawable background = layout.getBackground(); background.setAlpha(alphaValue); TextView textSetVariable = (TextView) view.findViewById(R.id.brick_change_variable_label); TextView textTo = (TextView) view.findViewById(R.id.brick_change_variable_by); TextView editVariable = (TextView) view.findViewById(R.id.brick_change_variable_edit_text); Spinner variablebrickSpinner = (Spinner) view.findViewById(R.id.change_variable_spinner); ColorStateList color = textSetVariable.getTextColors().withAlpha(alphaValue); variablebrickSpinner.getBackground().setAlpha(alphaValue); if (adapterView != null) { ((TextView) adapterView.getChildAt(0)).setTextColor(color); }/*from w w w.j a va 2 s.c om*/ textSetVariable.setTextColor(textSetVariable.getTextColors().withAlpha(alphaValue)); textTo.setTextColor(textTo.getTextColors().withAlpha(alphaValue)); editVariable.setTextColor(editVariable.getTextColors().withAlpha(alphaValue)); editVariable.getBackground().setAlpha(alphaValue); this.alphaValue = (alphaValue); } return view; }