本文整理汇总了Java中android.widget.TextView.setTextAlignment方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setTextAlignment方法的具体用法?Java TextView.setTextAlignment怎么用?Java TextView.setTextAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setTextAlignment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showBrandedSnackbar
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 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);
}
示例2: setMessageGravity
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 设置文字对齐方式(居中,靠左、靠右)
*
* @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;
}
示例3: getFilledTextView
import android.widget.TextView; //导入方法依赖的package包/类
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;
}
示例4: messageCenter
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 设置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;
}
示例5: messageRight
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 设置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;
}