bin*_*mic 10 android samsung-mobile android-6.0-marshmallow
仅在安装了Android 6.0的三星设备上才会出现此问题.它在所有其他设备上运行良好,包括安卓Android 6.0的非三星设备和Android 5.1及更低版本的三星设备.
目前我们没有任何带有Android 6.0的三星设备可以随时检查它,但我们很快就会安排它.
我们使用此功能:
用户长按TextView中的句子中的单词,然后用户可以编辑所选单词.
我们通过以下方式实现
我们面临的问题:
textView.getSelectionStart()返回正确的起始索引,但textView.getSelectionEnd()返回start index而不是end index的值.我们有一个保护条件,每当开始和结束索引相同时,选择是为了一个空格,因此我们忽略它,因此在Android 6.0及更高版本的三星设备上的所有单词选择都被忽略,导致功能失败.
我们尝试的事情:
代码片段:
tvText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false; // true = create the ActionMode
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode mode) {
}
});
tvText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
final TextView textView = (TextView) v;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//This works correct on all devices with Android 6.0
int startIndex = textView.getSelectionStart();
//This works wrong on Samsung devices with Android 6.0, result is same as getSelectionStart()
int endIndex = textView.getSelectionEnd();
//The guard condition where we ignore the empty selections
if ((endIndex - startIndex) <= 0) {
return;
}
// Do bunch of things to UI like applying some different foreground colors to the selected word, striking out selected word etc.
}
}, TEXT_LONG_PRESS_DELAY);
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
TextView的xml代码及其样式:
<TextView
android:id="@+id/tvText"
style="@style/StyleChatBubbleText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"/>
<style name="StyleChatBubbleText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">16dp</item>
<item name="android:textColor">@color/text_black</item>
<item name="android:textIsSelectable">true</item>
<item name="typeface">roboto_regular</item>
Run Code Online (Sandbox Code Playgroud)
有关此问题的任何帮助表示赞赏.
检查构建版本,如果 buildversion >= 6 返回 true ,使用您的自定义布局实现浮动工具栏。如果 buildversion <6 返回 false,则使用当前的实现
| 归档时间: |
|
| 查看次数: |
378 次 |
| 最近记录: |