android如下功能如何实现

img

img


如图,点击java.java文件后,显示出来代码页面,并且关键字有特定的颜色

获取方法(gradle)

compile 'thereisnospon.codeview:codeview:0.3.1'

然后就获取好了,如果有问题,那应该是被墙的锅。

具体使用方法,非常简单,首先在 layout文件中

 <thereisnospon.codeview.CodeView
        android:id="@+id/codeview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
</thereisnospon.codeview.CodeView>

然后在代码中使用它,就像这样

public class MainActivity extends AppCompatActivity {
    CodeView codeView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        codeView=(CodeView)findViewById(R.id.codeview);
        codeView.setTheme(CodeViewTheme.ANDROIDSTUDIO).fillColor();
        //这里的CODE 为需要显示的代码,类型为String,使用的时候自己替换下。
        codeView.showCode(CODE);
    }
}

没个电脑吗

把java文件里面的所有单词扫描出来,如果是匹配到对应的关键字的就给他换颜色。