如何在Android中应用复制的剪辑板文本样式

时间:2014-10-07 10:08:15

标签: android android-edittext clipboard

我有包含自定义字体的编辑文本。当我在编辑文本上双击时,文本将被复制到剪贴板以及当我粘贴在邮件应用程序上时。或其他应用程序。它将粘贴复制的文本但它不反映字体样式,它显示默认文本在下面的图像中显示。

enter image description here

enter image description here

这是我的示例代码,用于设置编辑文本的自定义字体和从编辑文本复制文本到剪贴板。

String Style = "C.A. Gatintas.ttf";
    face2 = Typeface.createFromAsset(getAssets(), "fonts/"
                    + style);
            edt2.setTypeface(face2);



@SuppressWarnings("deprecation")
        final GestureDetector gestureDetector = new GestureDetector(
                new GestureDetector.SimpleOnGestureListener() {
                    public boolean onDoubleTap(MotionEvent e) {

                        String text = edt2.getText().toString();
                        myClip = ClipData.newPlainText("text", text);
                        myClipboard.setPrimaryClip(myClip);
                        Toast.makeText(getApplicationContext(),
                                "Text Copied to Clip Board", Toast.LENGTH_SHORT)
                                .show();

                        return true;
                    }
                });

        edt2.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {

                return gestureDetector.onTouchEvent(event);
            }

        });

0 个答案:

没有答案