仅在具有Android 6.0的三星设备]上观察到此问题。在所有其他设备上都可以正常运行,包括非-装有Android 6.0的三星设备和装有Android 5.1及更低版本的三星设备。
[目前,我们没有任何带有Android 6.0的三星设备可以随时检查其上的东西,但我们会尽快进行安排。
我们正在使用的功能:
用户长按TextView中句子中的单词,然后用户可以编辑所选单词。
我们通过:]完成此操作
我们面临的问题:
textView.getSelectionStart()
我们尝试过的事情:
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;
}
});
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>
感谢您提供有关此问题的任何帮助。
仅在装有Android 6.0的Samsung设备上观察到此问题。在所有其他设备上都可以正常使用,包括非android 6.0的Samsung设备和android 5.1以及以下的Samsung设备。
检查内部版本如果buildversion> = 6返回true,则使用自定义布局实现一个浮动工具栏。如果buildversion <6返回false,请使用当前的实现