Skip to content

Commit

Permalink
加粗、斜体、标题等按钮自定义要被点击的view
Browse files Browse the repository at this point in the history
  • Loading branch information
yuruiyin committed Aug 22, 2019
1 parent 32583b8 commit 39e40c0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
18 changes: 12 additions & 6 deletions app/src/main/java/com/yuruiyin/richeditor/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class MainActivity : AppCompatActivity() {
RichTypeEnum.BOLD,
ivBold,
R.mipmap.icon_bold_normal,
R.mipmap.icon_bold_light
R.mipmap.icon_bold_light,
ivBold
)
)

Expand All @@ -120,7 +121,8 @@ class MainActivity : AppCompatActivity() {
RichTypeEnum.ITALIC,
ivItalic,
R.mipmap.icon_italic_normal,
R.mipmap.icon_italic_light
R.mipmap.icon_italic_light,
ivItalic
)
)

Expand All @@ -130,7 +132,8 @@ class MainActivity : AppCompatActivity() {
RichTypeEnum.STRIKE_THROUGH,
ivStrikeThrough,
R.mipmap.icon_strikethrough_normal,
R.mipmap.icon_strikethrough_light
R.mipmap.icon_strikethrough_light,
ivStrikeThrough
)
)

Expand All @@ -140,7 +143,8 @@ class MainActivity : AppCompatActivity() {
RichTypeEnum.UNDERLINE,
ivUnderline,
R.mipmap.icon_underline_normal,
R.mipmap.icon_underline_light
R.mipmap.icon_underline_light,
ivUnderline
)
)

Expand All @@ -150,7 +154,8 @@ class MainActivity : AppCompatActivity() {
RichTypeEnum.BLOCK_HEADLINE,
ivHeadline,
R.mipmap.icon_headline_normal,
R.mipmap.icon_headline_light
R.mipmap.icon_headline_light,
vgHeadline
)
)

Expand All @@ -160,7 +165,8 @@ class MainActivity : AppCompatActivity() {
RichTypeEnum.BLOCK_QUOTE,
ivBlockquote,
R.mipmap.icon_blockquote_normal,
R.mipmap.icon_blockquote_light
R.mipmap.icon_blockquote_light,
ivBlockquote
)
)

Expand Down
23 changes: 16 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,22 @@
android:src="@mipmap/icon_underline_normal"
/>

<ImageView
android:id="@+id/ivHeadline"
android:layout_width="@dimen/style_button_size"
android:layout_height="@dimen/style_button_size"
android:padding="7dp"
android:src="@mipmap/icon_headline_normal"
/>

<LinearLayout
android:id="@+id/vgHeadline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>

<ImageView
android:id="@+id/ivHeadline"
android:layout_width="@dimen/style_button_size"
android:layout_height="@dimen/style_button_size"
android:padding="7dp"
android:src="@mipmap/icon_headline_normal"
/>

</LinearLayout>

<ImageView
android:id="@+id/ivBlockquote"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void initStyleButton(StyleBtnVm styleBtnVm) {
String type = styleBtnVm.getType();
styleBtnVm.setIsInlineType(isInlineType(type));
mRichTypeToVmMap.put(type, styleBtnVm);
styleBtnVm.getIvButton().setOnClickListener(v -> {
styleBtnVm.getClickedView().setOnClickListener(v -> {
if (mRichEditText.isFocused()) {
// 若未聚焦,则不响应点击事件
toggleStyle(type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yuruiyin.richeditor.model;

import android.view.View;
import android.widget.ImageView;

import com.yuruiyin.richeditor.enumtype.RichTypeEnum;
Expand Down Expand Up @@ -43,12 +44,18 @@ public class StyleBtnVm {
*/
private int lightResId;

public StyleBtnVm(@RichTypeEnum String type, ImageView ivButton, int normalResId, int lightResId) {
/**
* 被点击的view
*/
private View clickedView;

public StyleBtnVm(@RichTypeEnum String type, ImageView ivButton, int normalResId, int lightResId, View clickedView) {
this.type = type;
this.ivButton = ivButton;
this.isLight = false;
this.normalResId = normalResId;
this.lightResId = lightResId;
this.clickedView = clickedView;
}

public String getType() {
Expand Down Expand Up @@ -98,4 +105,8 @@ public boolean isInlineType() {
public void setIsInlineType(boolean isInlineType) {
this.isInlineType = isInlineType;
}

public View getClickedView() {
return clickedView;
}
}

0 comments on commit 39e40c0

Please sign in to comment.