|
|
@ -443,11 +443,14 @@ public class NoteEditText extends androidx.appcompat.widget.AppCompatEditText {
|
|
|
|
public void showFormatToolbar() {//hzk -富文本编辑栏
|
|
|
|
public void showFormatToolbar() {//hzk -富文本编辑栏
|
|
|
|
if (mFormatToolbar == null) {
|
|
|
|
if (mFormatToolbar == null) {
|
|
|
|
// 初始化工具栏视图
|
|
|
|
// 初始化工具栏视图
|
|
|
|
|
|
|
|
//LayoutInflater.from(getContext()).inflate(R.layout.text_format_toolbar, null):
|
|
|
|
|
|
|
|
//通过 LayoutInflater 将布局文件 text_format_toolbar 转换为视图对象 mFormatToolbarView。这个布局文件定义了工具栏的外观和按钮。
|
|
|
|
mFormatToolbarView = LayoutInflater.from(getContext())
|
|
|
|
mFormatToolbarView = LayoutInflater.from(getContext())
|
|
|
|
.inflate(R.layout.text_format_toolbar, null);
|
|
|
|
.inflate(R.layout.text_format_toolbar, null);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置工具栏按钮点击事件
|
|
|
|
// 设置工具栏按钮点击事件,加粗功能
|
|
|
|
ImageButton boldButton = mFormatToolbarView.findViewById(R.id.btn_format_bold);
|
|
|
|
ImageButton boldButton = mFormatToolbarView.findViewById(R.id.btn_format_bold);
|
|
|
|
|
|
|
|
//setOnClickListener: 为按钮设置点击事件监听器,当按钮被点击时,调用 toggleBold() 方法切换选中文本的加粗效果。
|
|
|
|
boldButton.setOnClickListener(new OnClickListener() {
|
|
|
|
boldButton.setOnClickListener(new OnClickListener() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
@ -482,7 +485,7 @@ public class NoteEditText extends androidx.appcompat.widget.AppCompatEditText {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 创建PopupWindow
|
|
|
|
// 创建PopupWindow,工具显示栏
|
|
|
|
mFormatToolbar = new PopupWindow(
|
|
|
|
mFormatToolbar = new PopupWindow(
|
|
|
|
mFormatToolbarView,
|
|
|
|
mFormatToolbarView,
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
|
LinearLayout.LayoutParams.WRAP_CONTENT,
|
|
|
@ -490,11 +493,12 @@ public class NoteEditText extends androidx.appcompat.widget.AppCompatEditText {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置PopupWindow属性
|
|
|
|
// 设置PopupWindow属性
|
|
|
|
mFormatToolbar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
|
|
|
mFormatToolbar.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//设置背景为透明
|
|
|
|
mFormatToolbar.setOutsideTouchable(true);
|
|
|
|
mFormatToolbar.setOutsideTouchable(true);//允许点击外部区域关闭PopupWindow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 修改显示位置计算逻辑
|
|
|
|
// 修改显示位置计算逻辑
|
|
|
|
|
|
|
|
//getLocationInWindow(location): 获取当前视图在窗口中的位置,存储在 location 数组中。location[0] 是 x 坐标,location[1] 是 y 坐标。
|
|
|
|
int[] location = new int[2];
|
|
|
|
int[] location = new int[2];
|
|
|
|
getLocationInWindow(location);
|
|
|
|
getLocationInWindow(location);
|
|
|
|
|
|
|
|
|
|
|
|