下面列出了android.widget.TextView#setTransformationMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void setCustomAttr(TextView view) {
if (mTextColor != null)
view.setTextColor(mTextColor);
view.setTextSize(mTextSize);
int inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
switch (mPasswordType) {
case 1:
inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
break;
case 2:
inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
break;
case 3:
inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
break;
}
view.setInputType(inputType);
view.setTransformationMethod(mTransformationMethod);
}
public static $ pwd(boolean option){
try{
if(mView instanceof TextView){
TextView textView = (TextView) mView;
if(option)
textView.setTransformationMethod(new PasswordTransformationMethod());
else
textView.setTransformationMethod(null);
}
else if(mView instanceof EditText){
EditText editText = (EditText) mView;
if(option)
editText.setTransformationMethod(new PasswordTransformationMethod());
else
editText.setTransformationMethod(null);
}
}catch (Exception e){
Log.d(TAG, e.getMessage());
}
return $.getInstance();
}
/**
* Create a link from the text on the view
*
* @param v TextView
* @param text id of text to add to the field
*/
protected void createLink(TextView v, int text) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
v.setText(Html.fromHtml(getString(text), Html.FROM_HTML_MODE_LEGACY));
} else {
v.setText(Html.fromHtml(getString(text)));
}
v.setTransformationMethod(new LinkTransformationMethod());
v.setMovementMethod(LinkMovementMethod.getInstance());
}
/**
* Create a link from the text on the view
*
* @param v TextView
* @param text id of text to add to the field
*/
protected void createLink(TextView v, int text) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
v.setText(Html.fromHtml(getString(text), Html.FROM_HTML_MODE_LEGACY));
} else {
v.setText(Html.fromHtml(getString(text)));
}
v.setTransformationMethod(new LinkTransformationMethod());
v.setMovementMethod(LinkMovementMethod.getInstance());
}
/**
* Set the enabled state of this view.
*/
@Override
public void setPasswordVisibility(boolean visible) {
for (TextView textView : mViewArr) {
textView.setTransformationMethod(visible ? null : mTransformationMethod);
if (textView instanceof EditText) {
EditText et = (EditText) textView;
et.setSelection(et.getText().length());
}
}
}
/**
* Create a link from the text on the view
* @param v TextView
* @param text id of text to add to the field
*/
protected void createLink(TextView v, int text) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
v.setText(Html.fromHtml(getString(text), Html.FROM_HTML_MODE_LEGACY));
} else {
v.setText(Html.fromHtml(getString(text)));
}
v.setTransformationMethod(new LinkTransformationMethod());
v.setMovementMethod(LinkMovementMethod.getInstance());
}
/**
* Create a link from the text on the view
*
* @param v TextView
* @param text id of text to add to the field
*/
protected void createLink(TextView v, int text) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
v.setText(Html.fromHtml(getString(text), Html.FROM_HTML_MODE_LEGACY));
} else {
v.setText(Html.fromHtml(getString(text)));
}
v.setTransformationMethod(new LinkTransformationMethod());
v.setMovementMethod(LinkMovementMethod.getInstance());
}
public GroupViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.text_view_title);
textView.setTransformationMethod(
new AllCapsTransformationMethod(textView.getContext()));
weather = itemView.findViewById(R.id.weather);
textViewMorning = (TextView) itemView.findViewById(R.id.text_view_morning);
textViewAfternoon = (TextView) itemView.findViewById(R.id.text_view_afternoon);
textViewNight = (TextView) itemView.findViewById(R.id.text_view_night);
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Module module = mActivity.getModule();
if (module == null)
return null;
final View view = inflater.inflate(R.layout.download_details, container, false);
TextView title = view.findViewById(R.id.download_title);
title.setText(module.name);
title.setTextIsSelectable(true);
TextView author = view.findViewById(R.id.download_author);
if (module.author != null && !module.author.isEmpty())
author.setText(getString(R.string.download_author, module.author));
else
author.setText(R.string.download_unknown_author);
TextView description = view.findViewById(R.id.download_description);
if (module.description != null) {
if (module.descriptionIsHtml) {
description.setText(RepoParser.parseSimpleHtml(getActivity(), module.description, description));
description.setTransformationMethod(new LinkTransformationMethod(getActivity()));
description.setMovementMethod(LinkMovementMethod.getInstance());
} else {
description.setText(module.description);
}
description.setTextIsSelectable(true);
} else {
description.setVisibility(View.GONE);
}
ViewGroup moreInfoContainer = view.findViewById(R.id.download_moreinfo_container);
for (Pair<String, String> moreInfoEntry : module.moreInfo) {
View moreInfoView = inflater.inflate(R.layout.download_moreinfo, moreInfoContainer, false);
TextView txtTitle = moreInfoView.findViewById(android.R.id.title);
TextView txtValue = moreInfoView.findViewById(android.R.id.message);
txtTitle.setText(String.format(moreInfoEntry.first + "%s", ":"));
txtValue.setText(moreInfoEntry.second);
final Uri link = NavUtil.parseURL(moreInfoEntry.second);
if (link != null) {
txtValue.setTextColor(txtValue.getLinkTextColors());
moreInfoView.setOnClickListener(v -> NavUtil.startURL(getActivity(), link));
}
moreInfoContainer.addView(moreInfoView);
}
return view;
}
public void hideText() {
final TextView textView = (TextView) findViewById(R.id.text_view);
textView.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
public void showText() {
final TextView textView = (TextView) findViewById(R.id.text_view);
textView.setTransformationMethod(null);
}
public static void setSingleLineAllCaps(TextView text) {
text.setTransformationMethod(new SingleLineAllCapsTransform(text.getContext()));
}
public static void setSingleLineAllCaps(TextView text) {
text.setTransformationMethod(new SingleLineAllCapsTransform(text.getContext()));
}
public static void setSingleLineAllCaps(TextView text) {
text.setTransformationMethod(new SingleLineAllCapsTransform(text.getContext()));
}
public static void setSingleLineAllCaps(TextView text) {
text.setTransformationMethod(new SingleLineAllCapsTransform(text.getContext()));
}
public static void setSingleLineAllCaps(TextView text) {
text.setTransformationMethod(new SingleLineAllCapsTransform(text.getContext()));
}
public static void setSingleLineAllCaps(TextView text) {
text.setTransformationMethod(new SingleLineAllCapsTransform(text.getContext()));
}