-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f75adde
commit d77f9c8
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/me/yluo/ruisiapp/widget/htmlview/SelectFixTextView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package me.yluo.ruisiapp.widget.htmlview; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.Nullable; | ||
import android.text.Selection; | ||
import android.text.Spannable; | ||
import android.util.AttributeSet; | ||
import android.widget.TextView; | ||
|
||
|
||
/** | ||
* 修复 选择报错 | ||
* https://stackoverflow.com/questions/28689871/android-default-textselector-to-copy-text-not-working | ||
*/ | ||
public class SelectFixTextView extends TextView { | ||
public SelectFixTextView(Context context) { | ||
super(context); | ||
} | ||
|
||
public SelectFixTextView(Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public SelectFixTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
public SelectFixTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
} | ||
|
||
@Override | ||
protected void onSelectionChanged(int selStart, int selEnd) { | ||
if (selStart == -1 || selEnd == -1) { | ||
// @hack : https://code.google.com/p/android/issues/detail?id=137509 | ||
CharSequence text = getText(); | ||
if (text instanceof Spannable) { | ||
Selection.setSelection((Spannable) text, 0, 0); | ||
} | ||
} else { | ||
super.onSelectionChanged(selStart, selEnd); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters