Example usage for android.widget TextView getContext

List of usage examples for android.widget TextView getContext

Introduction

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

Prototype

@ViewDebug.CapturedViewProperty
public final Context getContext() 

Source Link

Document

Returns the context the view is running in, through which it can access the current theme, resources, etc.

Usage

From source file:Main.java

public static void setFont(TextView textView) {
    Typeface tf = Typeface.createFromAsset(textView.getContext().getAssets(), "font/ProximaNova-Reg.otf");
    textView.setTypeface(tf);/*  www . j a va  2  s . c  o  m*/
}

From source file:Main.java

public static void setFont(TextView t, String font) {
    Typeface type = Typeface.createFromAsset(t.getContext().getAssets(), font);
    t.setTypeface(type);/*  w ww.  j  a v  a2s  . co  m*/
}

From source file:Main.java

public static void applyFont(TextView textView, String fontPath) {
    Typeface fontFace = Typeface.createFromAsset(textView.getContext().getAssets(), fontPath);
    textView.setTypeface(fontFace);//from  ww w . j  a va 2  s.  com
}

From source file:Main.java

public static void setTextViewTypeface(TextView textView) {
    String font = "LockScreen_Clock.ttf";
    textView.setTypeface(Typeface.createFromAsset(textView.getContext().getAssets(), font));
}

From source file:Main.java

/**
 * @see android.widget.TextView#setTextAppearance(int id).
 *///from   w ww. jav  a 2  s  .c om
@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:cl.monsoon.s1next.binding.TextViewBindingAdapter.java

@BindingAdapter("textPath")
public static void loadTextAsset(TextView textView, String textPath) {
    try {/*from www . ja v  a 2s.c om*/
        InputStream inputStream = textView.getContext().getAssets().open(textPath);
        textView.setText(CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8)));
    } catch (IOException e) {
        throw new IllegalStateException("Can't find license.", e);
    }
}

From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java

@BindingAdapter("relativeDateTime")
public static void setRelativeDateTime(TextView textView, long datetime) {
    textView.setText(DateUtils.getRelativeDateTimeString(textView.getContext(), datetime,
            DateUtils.MINUTE_IN_MILLIS, DateUtils.DAY_IN_MILLIS, 0));
}

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 {/*  ww w.j  av a 2  s  .c om*/
        //noinspection deprecation
        textview.setTextAppearance(textview.getContext(), resId);
    }
}

From source file:android.support.v7.testutils.TestUtilsActions.java

/**
 * Sets text appearance on {@code TextView}.
 *//*ww  w  . j  a v a2 s.c  om*/
public static ViewAction setTextAppearance(final int resId) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return allOf(isDisplayingAtLeast(90), isAssignableFrom(TextView.class));
        }

        @Override
        public String getDescription() {
            return "TextView set text appearance";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();

            TextView textView = (TextView) view;
            textView.setTextAppearance(textView.getContext(), resId);

            uiController.loopMainThreadUntilIdle();
        }
    };
}

From source file:com.naman14.timber.adapters.SongsListAdapter.java

@BindingAdapter("bind:itemSongType")
public static void setItemViewStyles(TextView view, boolean isPlaylist) {
    if (isPlaylist) {
        view.setTextColor(ContextCompat.getColor(view.getContext(), android.R.color.white));
    }// ww  w. j a  v a  2s . c o  m
}