Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我能';不要让固定盘工作_Android_Spannablestring - Fatal编程技术网

Android 我能';不要让固定盘工作

Android 我能';不要让固定盘工作,android,spannablestring,Android,Spannablestring,我有一个细字体的字符串,例如:“@user liked your photo!2h ago” 这根绳子由三部分组成 1:@user->应该是字体,正常,可以点击 2:喜欢你的照片!->保持不变(薄且黑色) 3:2小时前->这应该是灰色的 Spannable spannedTime = new SpannableString(time); Spannable clickableUsername = new SpannableString(username); clickableUsername.s

我有一个细字体的字符串,例如:“@user liked your photo!2h ago”

这根绳子由三部分组成

1:@user->应该是字体,正常,可以点击

2:喜欢你的照片!->保持不变(薄且黑色)

3:2小时前->这应该是灰色的

Spannable spannedTime = new SpannableString(time);
Spannable clickableUsername = new SpannableString(username);
clickableUsername.setSpan(new StyleSpan(Typeface.NORMAL), 0, clickableUsername.length(), 0); // this is for 1st part to make it normal typeface
spannedTime.setSpan(new BackgroundColorSpan(Color.GRAY), 0, spannedTime.length(), 0); // this is for 3rd part to make it gray

clickableUsername.setSpan(new ClickableSpan() {
    @Override
    public void onClick(View view) {
        CallProfileActivity();
    }
}, 0, clickableUsername.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);// this is for 1st part to make it clickable

this.setText(clickableUsername + " " + notificationBody + " " + spannedTime);

但是它们都没有任何效果。

java编译器不知道
Spannable
。当你这样做的时候

this.setText(clickableUsername + " " + notificationBody + " " + spannedTime);
java创建一个包含所有
SpannableString
字符串

要创建您想要创建的可扩展字符串,应该使用


定义“不工作”。。。什么是
CallProfileActivity()要做什么?请参阅背景色span、样式span和可点击span它们都不起作用。CallProfileActivity();很好,它只是打开了一个活动。你能提供一个简单的例子,这样我们就可以重现这个问题了吗?
SpannableStringBuilder spannable = new SpannableStringBuilder();
spannable.append(clickableUsername, new StyleSpan(Typeface.NORMAL), 0);
spannable.append(' ').append(notificationBody).append(' ');
spannable.append(time, new BackgroundColorSpan(Color.GRAY), 0);
spannable.setSpan(new ClickableSpan() {
    @Override
    public void onClick(View view) {
        CallProfileActivity();
    }
}, 0, username.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
this.setText(spannable);