How set text in textview and formatted it as code? (Android Java) -
so question this. i'm writing app , want show part of "java code" in textview, when set text in textview looks simple text.
is possible show "code" code tag color, etc?
import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import br.tiagohm.codeview.language; import br.tiagohm.codeview.theme; import io.github.kbiakov.codeview.codeview; /** * simple {@link fragment} subclass. */ public class fragmentactivitytop extends fragment implements br.tiagohm.codeview.codeview.onhighlightlistener { codeview mcodeview; int tag=0; public fragmentactivitytop() { // required empty public constructor } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment //codeprocessor.init(getcontext()); view v =inflater.inflate(r.layout.activity_fragment_top, container, false); //codeview codeview = (codeview) v.findviewbyid(r.id.code_viewjava); string code = " @override\n" + " public view oncreateview(layoutinflater inflater, viewgroup container,\n" + " bundle savedinstancestate) {\n" + " // inflate layout fragment\n" + " view v = inflater.inflate(r.layout.fragment_xml, container, false);\n" + "\n" + " webview webview = (webview)v.findviewbyid(r.id.webfragxml);"; mcodeview = (codeview)v.findviewbyid(r.id.codeview); mcodeview.setonhighlightlistener(this) .setonhighlightlistener(this) .settheme(theme.agate) .setcode(code) .setlanguage(language.java) .setwrapline(true) .setfontsize(14) .setzoomenabled(true) .setshowlinenumber(true) .setstartlinenumber(9000) .apply(); return v; } @override public void onstartcodehighlight() { } @override public void onfinishcodehighlight() { } @override public void onlanguagedetected(language language, int i) { } @override public void onfontsizechanged(int i) { } @override public void onlineclicked(int i, string s) { } }
this fragment code when trying this: mcodeview.setonhighlightlistener(this)
setonhightkightlistener paint in red.
08-19 18:30:37.308 17929-17929/tj.horun.las.learnandroidstudio d/androidruntime: shutting down vm --------- beginning of crash
08-19 18:30:37.314 17929-17929/tj.horun.las.learnandroidstudio e/androidruntime: fatal exception: main process: tj.horun.las.learnandroidstudio, pid: 17929 android.view.inflateexception: binary xml file line #8: binary xml file line #8: error inflating class io.github.kbiakov.codeview.codeview caused by: android.view.inflateexception: binary xml file line #8: error inflating class io.github.kbiakov.codeview.codeview caused by: java.lang.classnotfoundexception: didn't find class "io.github.kbiakov.codeview.codeview" on path: dexpathlist[[zip file "/data/app/tj.horun.las.learnandroidstudio-1/base.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_dependencies_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_0_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_1_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_2_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_3_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_4_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_5_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_6_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_7_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_8_apk.apk", zip file "/data/app/tj.horun.las.learnandroidstudio-1/split_lib_slice_9_apk.apk"],nativelibrarydirectories=[/data/app/tj.horun.las.learnandroidstudio-1/lib/arm64, /system/lib64, /vendor/lib64]] @ dalvik.system.basedexclassloader.findclass(basedexclassloader.java:56) @ java.lang.classloader.loadclass(classloader.java:380) @ java.lang.classloader.loadclass(classloader.java:312) @ android.view.layoutinflater.createview(layoutinflater.java:609) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:787) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:727) @ android.view.layoutinflater.rinflate(layoutinflater.java:858) @ android.view.layoutinflater.rinflatechildren(layoutinflater.java:821) @ android.view.layoutinflater.inflate(layoutinflater.java:518) @ android.view.layoutinflater.inflate(layoutinflater.java:426) @ tj.horun.las.learnandroidstudio.layoutfragment.oncreateview(layoutfragment.java:28) @ android.support.v4.app.fragment.performcreateview(fragment.java:2239) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1332) @ android.support.v4.app.fragmentmanagerimpl.movefragmenttoexpectedstate(fragmentmanager.java:1574) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1641) @ android.support.v4.app.backstackrecord.executeops(backstackrecord.java:794) @ android.support.v4.app.fragmentmanagerimpl.executeops(fragmentmanager.java:2415) @ android.support.v4.app.fragmentmanagerimpl.executeopstogether(fragmentmanager.java:2200) @ android.support.v4.app.fragmentmanagerimpl.optimizeandexecuteops(fragmentmanager.java:2153) @ android.support.v4.app.fragmentmanagerimpl.execsingleaction(fragmentmanager.java:2034) @ android.support.v4.app.backstackrecord.commitnowallowingstateloss(backstackrecord.java:651) @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:143) @ android.support.v4.view.viewpager.populate(viewpager.java:1239) @ android.support.v4.view.viewpager.populate(viewpager.java:1087) @ android.support.v4.view.viewpager$3.run(viewpager.java:270) @ android.view.choreographer$callbackrecord.run(choreographer.java:874) @ android.view.choreographer.docallbacks(choreographer.java:686) @ android.view.choreographer.doframe(choreographer.java:618) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:860) @ android.os.handler.handlecallback(handler.java:751) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:241) @ android.app.activitythread.main(activitythread.java:6274) 08-19 18:30:37.315 17929-17929/tj.horun.las.learnandroidstudio e/androidruntime: @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:886) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:776)
you can use this library enable code highlighting.
Comments
Post a Comment