本文整理汇总了Java中android.text.Html.fromHtml方法的典型用法代码示例。如果您正苦于以下问题:Java Html.fromHtml方法的具体用法?Java Html.fromHtml怎么用?Java Html.fromHtml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.Html
的用法示例。
在下文中一共展示了Html.fromHtml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFormattedTitle
import android.text.Html; //导入方法依赖的package包/类
@Override
public CharSequence getFormattedTitle(Context context, int viewMode) {
String ret = null;
if (mShowTitle != null) {
// Build the first part of the title: "show name + SxEy"
ret = String.format(TITLE_FORMAT, mShowTitle, mSeasonNumber, mEpisodeNumber);
if (viewMode == VideoUtils.VIEW_MODE_LIST) {
// Append the episode name in italics: " <<episode name>>"
String episodeNameFormat = context.getString(R.string.quotation_format);
String episodeName = String.format(episodeNameFormat, mEpisodeTitle);
return Html.fromHtml(ret + " <i>" + episodeName + "</i>");
}
}
return ret;
}
示例2: setErrorHint
import android.text.Html; //导入方法依赖的package包/类
/**
* Set the hint for an EditText to the specified string on error
*
* @param editText edit widget
* @param resId string resource
*/
private void setErrorHint(EditText editText, @StringRes int resId)
{
String html = "<font color='#ff0000'>" + getResources().getText(resId) + "</font>";
CharSequence hint;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N)
{
hint = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
}
else
{
//noinspection deprecation
hint = Html.fromHtml(html);
}
editText.setHint(hint);
}
示例3: onPostsLoadedEvent
import android.text.Html; //导入方法依赖的package包/类
@Subscribe
public void onPostsLoadedEvent(PostsLoadedEvent event) {
// this exists to let animation run to completion because posts are loaded
// twice on launch: once cached data, and once from the network
if (mPosts.equals(event.posts)) {
return;
}
mPosts.clear();
mPosts.addAll(event.posts);
if (mPosts.size() >= event.postsFetchLimit) {
CharSequence message = Html.fromHtml(getString(R.string.post_limit_exceeded,
getString(R.string.app_name), event.postsFetchLimit,
"https://github.com/vickychijwani/quill/issues/81"));
mPostAdapter.showFooter(message);
} else {
mPostAdapter.hideFooter();
}
mPostAdapter.notifyDataSetChanged();
}
示例4: fromHtml
import android.text.Html; //导入方法依赖的package包/类
public static Spanned fromHtml(String html){
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= 24) {
result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
}
return result;
}
示例5: fromHtml
import android.text.Html; //导入方法依赖的package包/类
/**
* Helper class to handle deprecated method.
* Source: http://stackoverflow.com/questions/37904739/html-fromhtml-deprecated-in-android-n
* @param html html string
* @return Spanned
*/
@SuppressWarnings("deprecation")
public static Spanned fromHtml(String html){
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(html,Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
}
return result;
}
示例6: getView
import android.text.Html; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = LayoutInflater.from(getContext()).inflate(resource, null);
ContactItem contact = getItem(position);
if (contact != null) {
String html = "<b>" + contact.name + "</b> " + contact.number;
Spanned newText;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
newText = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
else
newText = Html.fromHtml(html);
CheckedTextView textView = (CheckedTextView) convertView;
textView.setText(newText);
textView.setChecked(contact.checked);
textView.jumpDrawablesToCurrentState(); // (!!!) Ferma l'animazione dovuta a setChecked, terribile quando vengono riciclate le view
}
return convertView;
}
示例7: onCreateDialog
import android.text.Html; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
//noinspection unchecked
final ArrayList<PlaylistSong> songs = getArguments().getParcelableArrayList("songs");
int title;
CharSequence content;
if (songs.size() > 1) {
title = R.string.remove_songs_from_playlist_title;
content = Html.fromHtml(getString(R.string.remove_x_songs_from_playlist, songs.size()));
} else {
title = R.string.remove_song_from_playlist_title;
content = Html.fromHtml(getString(R.string.remove_song_x_from_playlist, songs.get(0).title));
}
return new MaterialDialog.Builder(getActivity())
.title(title)
.content(content)
.positiveText(R.string.remove_action)
.negativeText(android.R.string.cancel)
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (getActivity() == null)
return;
PlaylistsUtil.removeFromPlaylist(getActivity(), songs);
}
})
.build();
}
示例8: fromHtml
import android.text.Html; //导入方法依赖的package包/类
public static Spanned fromHtml(String text) {
if(Utils.hasNougat()){
return Html.fromHtml(text, 0);
} else {
return Html.fromHtml(text);
}
}
示例9: formatText
import android.text.Html; //导入方法依赖的package包/类
protected Spanned formatText(String text) {
if (text == null) {
return null;
}
if (text.matches(".*\\de[-" + Constants.MINUS + "]?\\d.*")) {
text = text.replace("e", Constants.MUL + "10^");
}
return Html.fromHtml(
mEquationFormatter.insertSupScripts(
mEquationFormatter.addComas(mSolver, text)));
}
示例10: fromHtml
import android.text.Html; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public Spanned fromHtml(String source) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
} else {
return Html.fromHtml(source);
}
}
示例11: checkPermission
import android.text.Html; //导入方法依赖的package包/类
public void checkPermission(CheckPermListener listener, int resString, String... mPerms) {
mListener = listener;
if (EasyPermissions.hasPermissions(this, mPerms)) {
if (mListener != null)
mListener.grantPermission();
} else {
CharSequence text= Html.fromHtml("<font color=\"#000000\">"+getString(resString)+"</font>");
EasyPermissions.requestPermissions(this, text,
RC_PERM, mPerms);
}
}
示例12: fromHtml
import android.text.Html; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static Spanned fromHtml(String source) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
} else {
return Html.fromHtml(source);
}
}
示例13: onCreate
import android.text.Html; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_terms);
String htmlAsString = getString(R.string.privacy_policy_html);
Spanned htmlAsSpanned;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
htmlAsSpanned = Html.fromHtml(htmlAsString,Html.FROM_HTML_MODE_LEGACY);
} else {
htmlAsSpanned = Html.fromHtml(htmlAsString);
}
// set the html content on a TextView
TextView textView = (TextView) findViewById(R.id.textView_privacy_policy);
textView.setText(htmlAsSpanned);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
Button ok = (Button) findViewById(R.id.privacy_policy_button);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
prefs.edit().putBoolean("terms_shown", true).apply();
finish();
}
});
}
示例14: fromHtml
import android.text.Html; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static Spanned fromHtml(String html) {
Spanned result;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
result = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
} else {
result = Html.fromHtml(html);
}
return result;
}
示例15: decode
import android.text.Html; //导入方法依赖的package包/类
@Override
protected SubripSubtitle decode(byte[] bytes, int length, boolean reset) {
ArrayList<Cue> cues = new ArrayList<>();
LongArray cueTimesUs = new LongArray();
ParsableByteArray subripData = new ParsableByteArray(bytes, length);
String currentLine;
while ((currentLine = subripData.readLine()) != null) {
if (currentLine.length() == 0) {
// Skip blank lines.
continue;
}
// Parse the index line as a sanity check.
try {
Integer.parseInt(currentLine);
} catch (NumberFormatException e) {
Log.w(TAG, "Skipping invalid index: " + currentLine);
continue;
}
// Read and parse the timing line.
boolean haveEndTimecode = false;
currentLine = subripData.readLine();
Matcher matcher = SUBRIP_TIMING_LINE.matcher(currentLine);
if (matcher.matches()) {
cueTimesUs.add(parseTimecode(matcher, 1));
if (!TextUtils.isEmpty(matcher.group(6))) {
haveEndTimecode = true;
cueTimesUs.add(parseTimecode(matcher, 6));
}
} else {
Log.w(TAG, "Skipping invalid timing: " + currentLine);
continue;
}
// Read and parse the text.
textBuilder.setLength(0);
while (!TextUtils.isEmpty(currentLine = subripData.readLine())) {
if (textBuilder.length() > 0) {
textBuilder.append("<br>");
}
textBuilder.append(currentLine.trim());
}
Spanned text = Html.fromHtml(textBuilder.toString());
cues.add(new Cue(text));
if (haveEndTimecode) {
cues.add(null);
}
}
Cue[] cuesArray = new Cue[cues.size()];
cues.toArray(cuesArray);
long[] cueTimesUsArray = cueTimesUs.toArray();
return new SubripSubtitle(cuesArray, cueTimesUsArray);
}