gpt4 book ai didi

java - Android 为文本添加下划线并保存到文本文件

转载 作者:行者123 更新时间:2023-12-01 12:05:20 25 4
gpt4 key购买 nike

我正在尝试在 Java 中为文本添加下划线。 attendeeList 项目来 self 的数据库。这是我的代码:

for (int i = 0; i < attendeeList.size(); i++) {
attendeeCounterStr = "\nAttendee " + counter;
attendeeStrBuilder.append(attendeeCounterStr);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Font plainFont = new Font("Times New Roman", Font.PLAIN, 24);

AttributedString as = new AttributedString(
attendeeCounterStr);
as.addAttribute(TextAttribute.FONT, plainFont);
as.addAttribute(TextAttribute.UNDERLINE,
TextAttribute.UNDERLINE_ON, 0, 10);
g.drawString(as.getIterator(), 24, 70);

counter++;
}

我的文本示例是:Attendee 1Attendee 2 等。但是,我收到这样的错误消息:

12-27 16:26:34.921: D/BounceScrollRunnableDefault(26975): start(1439.7937), mBounceExtent:0.0
12-27 16:26:34.991: D/BounceScrollRunnableDefault(26975): mBounceExtentCoef = -118.639
12-27 16:26:35.585: W/dalvikvm(26975): VFY: unable to resolve static field 11624 (KEY_ANTIALIASING) in Ljava/awt/RenderingHints;
12-27 16:26:35.585: D/dalvikvm(26975): VFY: replacing opcode 0x62 at 0x010e
12-27 16:26:35.585: I/dalvikvm(26975): DexOpt: unable to optimize static field ref 0x2d69 at 0x110 in Lnyp/edu/eneighbourhood/EventDetailChart$4;.onClick
12-27 16:26:35.585: D/dalvikvm(26975): DexOpt: unable to opt direct call 0x717e at 0x121 in Lnyp/edu/eneighbourhood/EventDetailChart$4;.onClick
12-27 16:26:37.054: D/AndroidRuntime(26975): Shutting down VM
12-27 16:26:37.054: W/dalvikvm(26975): threadid=1: thread exiting with uncaught exception (group=0x40c561f8)
12-27 16:26:37.249: E/AndroidRuntime(26975): FATAL EXCEPTION: main
12-27 16:26:37.249: E/AndroidRuntime(26975): java.lang.NoClassDefFoundError: java.awt.RenderingHints
12-27 16:26:37.249: E/AndroidRuntime(26975): at nyp.edu.eneighbourhood.EventDetailChart$4.onClick(EventDetailChart.java:227)
12-27 16:26:37.249: E/AndroidRuntime(26975): at android.view.View.performClick(View.java:3620)
12-27 16:26:37.249: E/AndroidRuntime(26975): at android.view.View$PerformClick.run(View.java:14292)
12-27 16:26:37.249: E/AndroidRuntime(26975): at android.os.Handler.handleCallback(Handler.java:605)
12-27 16:26:37.249: E/AndroidRuntime(26975): at android.os.Handler.dispatchMessage(Handler.java:92)
12-27 16:26:37.249: E/AndroidRuntime(26975): at android.os.Looper.loop(Looper.java:137)
12-27 16:26:37.249: E/AndroidRuntime(26975): at android.app.ActivityThread.main(ActivityThread.java:4512)
12-27 16:26:37.249: E/AndroidRuntime(26975): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 16:26:37.249: E/AndroidRuntime(26975): at java.lang.reflect.Method.invoke(Method.java:511)
12-27 16:26:37.249: E/AndroidRuntime(26975): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
12-27 16:26:37.249: E/AndroidRuntime(26975): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
12-27 16:26:37.249: E/AndroidRuntime(26975): at dalvik.system.NativeStart.main(Native Method)
12-27 16:27:11.726: I/Process(26975): Sending signal. PID: 26975 SIG: 9

最佳答案

这不是在 Android 上为文本添加下划线的正确方法。你想要这样的东西:

TextView textView = (TextView) view.findViewById(R.id.viewid);
SpannableString content = new SpannableString("Something to be underlined");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
textView.setText(content);

关于java - Android 为文本添加下划线并保存到文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27665635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com