Giter Site home page Giter Site logo

zktzktzkt / advancedtextview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from devilist/advancedtextview

0.0 1.0 0.0 8.04 MB

文字两端对齐,宽度自适应,长按选中文本 - 一个增强的TextView库。可以实现文字两端对齐,文字竖排,以及自定义选择文字后的弹出菜单。

License: Apache License 2.0

Java 100.00%

advancedtextview's Introduction

AdvancedTextView

这是一个增强的TextView库。可以实现文字的两端对齐,文字竖排,以及自定义的弹出菜单。

具体介绍请移步博客:

https://blog.csdn.net/devilist/article/details/54911641

https://blog.csdn.net/devilist/article/details/79236665

本库目前提供两个控件 SelectableTextView 和 VerticalTexview。

1. SelectableTextView

image

在布局中引用:

 <com.devilist.advancedtextview.SelectableTextView
      android:id="@+id/ctv_content"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="10dp"
      android:background="#FDFBF8"
      android:lineSpacingMultiplier="1.5"
      android:padding="5dp"
      android:textColor="#808080"
      android:textSize="16sp"
      app:forbiddenActionMenu="false"                     // 是否禁用自定义ActionMenu
      app:textHeightColor="@color/colorAccent"            // 文本高亮色
      app:textJustify="false" />                          // 是否启用两端对齐

也可以在代码中设置:

        selectableTextView.setTextJustify(true);                  // 是否启用两端对齐 默认启用 
        selectableTextView.setForbiddenActionMenu(false);         // 是否禁用自定义ActionMenu 默认启用
        selectableTextView.setTextHighlightColor(0xff48543e);     // 文本高亮色

注意:在代码中调用上述三个方法后需要 调用 inviladite() 或 postInviladite()方法通知View重绘

设置ActionMenu菜单点击监听:

selectableTextView.setCustomActionMenuCallBack(new CustomActionMenuCallBack() {
    @Override
        public boolean onCreateCustomActionMenu(ActionMenu menu) {
            menu.setActionMenuBgColor(0xff666666);                    // ActionMenu背景色
            menu.setMenuItemTextColor(0xffffffff);                   // ActionMenu文字颜色
            List<String> titleList = new ArrayList<>();
            titleList.add("翻译");
            titleList.add("分享");
            titleList.add("分享");
            menu.addCustomMenuItem(titleList);                       // 添加菜单
            return false;                                            // 返回false,保留默认菜单(全选/复制);返回true,移除默认菜单
     }
     
    @Override
        public void onCustomActionItemClicked(String itemTitle, String selectedContent) {
            Toast.makeText(this, "ActionMenu: " + itemTitle, Toast.LENGTH_SHORT).show();
     }
});

2. VerticalTextView

image

在布局中引用:

<com.devilist.advancedtextview.VerticalTextView
            android:id="@+id/vtv_text_ltr"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#FDFBF8"
            android:gravity="center"
            android:padding="15dp"
            android:textColor="#808080"
            android:textSize="16sp"
            app:charSpacingExtra="2dp"                              // 字符间距
            app:lineSpacingExtra="15dp"                             // 行间距
            app:showActionMenu="true"                               // 是否开启ActionMenu,默认关闭
            app:textLeftToRight="true"                              // 文字是否从左向右排版,默认从右向左排版
            app:underLineText="true"                                // 是否显示下划线,默认不显示
            app:underLineColor="#CEAD53"                            // 下划线颜色
            app:underLineWidth="2.5"                                // 下划线线宽
            app:textHeightLightColor="@color/colorAccent"           // 选中文字高亮色
            app:underlineOffset="3dp" />                            // 下划线偏移量

在代码中设置:

    vtv_text_ltr.setLeftToRight(true)                  // 文字是否从左向右排版,默认从右向左排版
                .setLineSpacingExtra(10)               // 行间距
                .setCharSpacingExtra(2)                // 字符间距
                .setUnderLineText(true)                // 是否显示下划线,默认不显示
                .setShowActionMenu(true)               // 是否开启ActionMenu,默认关闭
                .setUnderLineColor(0xffCEAD53)         // 下划线颜色
                .setUnderLineWidth(1.0f)               // 下划线线宽
                .setUnderLineOffset(3)                 // 下划线偏移量
                .setTextHighlightColor(0xffCEAD53)     // 选中文字高亮色
                .setCustomActionMenuCallBack(this);    // ActionMenu菜单点击监听

注意:在代码中调用上述方法后需要 调用 requestLayout()方法通知View重新布局

设置ActionMenu菜单点击监听和SelectableTextView一样。

advancedtextview's People

Contributors

devilist avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.