我有這個代碼從TextView
複製到剪貼板,但如果您不添加android:textIsSelectable="true"
此代碼不起作用。爲什麼? 我的意思是,如果您不使用此代碼,只需添加android:textIsSelectable="true"
,您可以將TextView
複製到剪貼板,但在API> = 11中,因此當我使用此代碼的API < 11時,我預計它的工作不會添加android:textIsSelectable="true"
,噸。爲什麼?爲什麼沒有「android:textIsSelectable =」true「」這個簡單的代碼不能工作?
txt=(TextView)findViewById(R.id.txt);
final int startIndex = txt.getSelectionStart();
final int endIndex = txt.getSelectionEnd();
final String stringYouExtracted = txt.getText().toString().substring(startIndex, endIndex);
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
clipboard.setText(stringYouExtracted);
你應該接受我的答案,以避免保留這個問題沒有答案。我寫這個是因爲從你最後的回答中你明白我在答案中寫的是什麼。 –