android 横向竖排文字,GitHub - tung666/AdvancedTextView: 一个增强的TextView库。可以实现文字两端对齐,文字竖排,以及自定义选择文字后的弹出菜单。...
AdvancedTextView
這是一個增強的TextView庫。可以實現文字的兩端對齊,文字豎排,以及自定義的彈出菜單。
具體介紹請移步博客:
本庫目前提供兩個控件 SelectableTextView 和 VerticalTexview。
1. 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 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
在布局中引用:
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一樣。
總結
以上是生活随笔為你收集整理的android 横向竖排文字,GitHub - tung666/AdvancedTextView: 一个增强的TextView库。可以实现文字两端对齐,文字竖排,以及自定义选择文字后的弹出菜单。...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 渐变橡皮擦_java 的画板
- 下一篇: Weblogic Server打补丁方法