List of usage examples for android.widget TextView setTextAppearance
@SuppressWarnings("deprecation") public void setTextAppearance(@StyleRes int resId)
From source file:Main.java
/** * @see android.widget.TextView#setTextAppearance(int id). *//* w w w . j av a 2s. co m*/ @SuppressWarnings("deprecation") public static void setTextAppearance(TextView view, int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { view.setTextAppearance(id); } else { view.setTextAppearance(view.getContext(), id); } }
From source file:Main.java
public static void setTextAppearance(TextView textview, int resId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textview.setTextAppearance(resId); } else {/*from ww w .j av a2s.c om*/ //noinspection deprecation textview.setTextAppearance(textview.getContext(), resId); } }
From source file:Main.java
public static void setTextAppearance(TextView tv, @StyleRes int textAppearanceRes) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { tv.setTextAppearance(textAppearanceRes); } else {//from ww w . j a va2 s.c om //noinspection deprecation tv.setTextAppearance(tv.getContext(), textAppearanceRes); } }
From source file:com.example.ray.firstapp.bottombar.MiscUtils.java
/** * A convenience method for setting text appearance. * * @param textView a TextView which textAppearance to modify. * @param resId a style resource for the text appearance. *///from w w w.j av a2 s. c o m @SuppressWarnings("deprecation") protected static void setTextAppearance(TextView textView, int resId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textView.setTextAppearance(resId); } else { textView.setTextAppearance(textView.getContext(), resId); } }
From source file:com.murrayc.galaxyzoo.app.QuestionHelpFragment.java
private void addRowForAnswer(final Context context, final TableLayout tableLayout, final DecisionTree.Question question, final DecisionTree.BaseButton answer) { final TableRow row = new TableRow(context); final TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin), 0, 0); tableLayout.addView(row, params);/*from w w w .ja va2 s .c o m*/ final LinearLayout layoutVertical = new LinearLayout(context); layoutVertical.setOrientation(LinearLayout.VERTICAL); final TextView textViewAnswer = new AppCompatTextView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textViewAnswer.setTextAppearance(R.style.TextAppearance_AppCompat_Subhead); } else { //noinspection deprecation textViewAnswer.setTextAppearance(context, R.style.TextAppearance_AppCompat_Subhead); } textViewAnswer.setText(answer.getText()); layoutVertical.addView(textViewAnswer, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final LinearLayout layoutHorizontal = new LinearLayout(context); layoutHorizontal.setOrientation(LinearLayout.HORIZONTAL); final LinearLayout.LayoutParams paramsHorizontal = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); paramsHorizontal.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_margin), 0, 0); layoutVertical.addView(layoutHorizontal, paramsHorizontal); final BitmapDrawable icon = getIcon(context, answer); final ImageView imageIcon = new ImageView(context); imageIcon.setImageDrawable(icon); layoutHorizontal.addView(imageIcon); final LinearLayout.LayoutParams paramsImage = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); // TODO: Use a custom FlowTable class to avoid items going off the right edge of the screen // when there are too many. final Singleton singleton = getSingleton(); for (int i = 0; i < answer.getExamplesCount(); i++) { final String iconName = answer.getExampleIconName(question.getId(), i); final BitmapDrawable iconExample = singleton.getIconDrawable(context, iconName); final ImageButton imageExample = new ImageButton(context); //Remove the space between the image and the outside of the button: imageExample.setPadding(0, 0, 0, 0); imageExample.setImageDrawable(iconExample); //Needed to make the image expand as a transition into the SubjectViewerActivity, //which uses the same name in fragment_subject.xml ViewCompat.setTransitionName(imageExample, getString(R.string.transition_subject_image)); //This requires API level 17: paramsImage.setMarginStart(getPxForDp(activity, MARGIN_MEDIUM_DP)); //imageExample.setLayoutParams(paramsImage); MarginLayoutParamsCompat.setMarginStart(paramsImage, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin)); final int answerIndex = i; imageExample.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { // Perform action on click onExampleImageClicked(v, answer, answerIndex); } }); layoutHorizontal.addView(imageExample, paramsImage); } row.addView(layoutVertical, new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); }
From source file:com.github.antoniodisanto92.swipeselector.SwipeAdapter.java
@SuppressWarnings("deprecation") private void setTextAppearanceCompat(TextView textView, int appearanceRes) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textView.setTextAppearance(appearanceRes); } else {//from ww w. ja v a2 s . co m textView.setTextAppearance(textView.getContext(), appearanceRes); } }
From source file:nz.ac.auckland.lablet.script.components.TextComponent.java
@Override public View createView(Context context, android.support.v4.app.Fragment parent) { TextView textView = new TextView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textView.setTextAppearance(android.R.style.TextAppearance_Medium); } else {//from ww w.ja v a 2s . co m textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); } textView.setTypeface(null, typeface); textView.setText(text); return textView; }
From source file:nz.ac.auckland.lablet.script.components.TextComponent.java
@Override public View createView(Context context, android.support.v4.app.Fragment parent) { // we have to get a fresh counter here, if we cache it we will miss that it has been deleted in the sheet // component/*from ww w .j a v a 2s .c o m*/ ScriptTreeNodeSheetBase.Counter counter = this.component.getCounter("QuestionCounter"); TextView textView = new TextView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textView.setTextAppearance(android.R.style.TextAppearance_Medium); textView.setBackgroundColor( context.getResources().getColor(R.color.sc_question_background_color, null)); } else { textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); textView.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color)); } textView.setText("Q" + counter.increaseValue() + ": " + text); return textView; }
From source file:nz.ac.auckland.lablet.script.components.TextComponent.java
@Override public View createView(Context context, Fragment parent) { ScriptTreeNodeSheetBase.Counter counter = this.component.getCounter("QuestionCounter"); // Note: we have to do this programmatically because findViewById would find the wrong child // items if there is more than one text question. LinearLayout layout = new LinearLayout(context); layout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.setOrientation(LinearLayout.VERTICAL); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { layout.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color, null)); } else {//from w w w . j a va 2 s .c o m layout.setBackgroundColor(context.getResources().getColor(R.color.sc_question_background_color)); } TextView textView = new TextView(context); textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textView.setTextAppearance(android.R.style.TextAppearance_Medium); } else { textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); } question_num = counter.increaseValue(); textView.setText("Q" + question_num + ": " + text); EditText editText = new EditText(context); editText.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); editText.setText(answer); editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { answer = editable.toString(); update(); } }); layout.addView(textView); layout.addView(editText); return layout; }
From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java
/** * Applies the specified text appearance resource to a paint, returning the * text color if one is set in the text appearance. * * @param p the paint to modify//w w w . j a v a2 s . c o m * @param resId the resource ID of the text appearance * @return the text color, if available */ private ColorStateList applyTextAppearance(Paint p, int resId) { // Workaround for inaccessible R.styleable.TextAppearance_* TextView tv = new TextView(mContext); if (SUtils.isApi_23_OrHigher()) { tv.setTextAppearance(resId); } else { //noinspection deprecation tv.setTextAppearance(mContext, resId); } p.setTypeface(tv.getTypeface()); p.setTextSize(tv.getTextSize()); final ColorStateList textColor = tv.getTextColors(); if (textColor != null) { final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0); p.setColor(enabledColor); } return textColor; }