Java Code Examples for android.widget.TextView.setTextAlignment()

The following are Jave code examples for showing how to use setTextAlignment() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: firefox-tv   File: ViewUtils.java   Source Code and License Vote up 6 votes
/**
 * Create a snackbar with Focus branding (See #193).
 */
public static void showBrandedSnackbar(View view, @StringRes int resId, int delayMillis) {
    final Context context = view.getContext();
    final Snackbar snackbar = Snackbar.make(view, resId, Snackbar.LENGTH_LONG);

    final View snackbarView = snackbar.getView();
    snackbarView.setBackgroundColor(ContextCompat.getColor(context, R.color.snackbarBackground));

    final TextView snackbarTextView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
    snackbarTextView.setTextColor(ContextCompat.getColor(context, R.color.snackbarTextColor));
    snackbarTextView.setGravity(Gravity.CENTER);
    snackbarTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);

    view.postDelayed(new Runnable() {
        @Override
        public void run() {
            snackbar.show();
        }
    }, delayMillis);
}
 
Example 2
Project: MVVMFrames   File: ToastBar.java   Source Code and License Vote up 5 votes
/**
 * 设置文字对齐方式(居中,靠左、靠右)
 *
 * @param gravity
 * @return ToastBar
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private ToastBar setMessageGravity(int gravity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView message = (TextView) snackbar.getView().findViewById(R.id.snackbar_text);
        // View.setTextAlignment需要SDK>=17
        message.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
        message.setGravity(Gravity.CENTER_VERTICAL | gravity);
    }
    return this;
}
 
Example 3
Project: CP-Tester   File: ViewHelper.java   Source Code and License Vote up 5 votes
public static TextView getFilledTextView(Context context,String text){
    TextView tv = new TextView(context);
    tv.setText(text);
    tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    tv.setTextColor(Color.parseColor("#dd2c00"));
    tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    tv.setTypeface(Typeface.DEFAULT_BOLD);
    tv.setTextSize(20);
    tv.setPadding(0,0,0,10);
    return tv;
}
 
Example 4
Project: PicKing   File: SnackbarUtils.java   Source Code and License Vote up 5 votes
/**
 * 设置TextView(@+id/snackbar_text)中文字的对齐方式 居中
 *
 * @return
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public SnackbarUtils messageCenter() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        if (getSnackbar() != null) {
            TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
            //View.setTextAlignment需要SDK>=17
            message.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
            message.setGravity(Gravity.CENTER);
        }
    }
    return this;
}
 
Example 5
Project: PicKing   File: SnackbarUtils.java   Source Code and License Vote up 5 votes
/**
 * 设置TextView(@+id/snackbar_text)中文字的对齐方式 居右
 *
 * @return
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public SnackbarUtils messageRight() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        if (getSnackbar() != null) {
            TextView message = (TextView) getSnackbar().getView().findViewById(R.id.snackbar_text);
            //View.setTextAlignment需要SDK>=17
            message.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
            message.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
        }
    }
    return this;
}