如何在Android上长按Listener编辑贴纸视图文本

时间:2017-07-13 06:32:03

标签: android news-ticker msstickerview

我正在开发贴纸应用程序,我可以在其中添加文本到Stickerview。我可以翻转,旋转和删除贴纸文字。现在我想在长按clickText时编辑StickerView的文本。 这是将文字贴纸添加到屏幕的代码。

    imgText.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v) {
            isEffectsVisible = isSttickerVisible = false;
            gridView.setVisibility(View.GONE);
            recycler_Effect.setVisibility(View.GONE);
            recyclerView.setVisibility(View.GONE);
            final Dialog dialog = new Dialog(MainActivity.this);
            // Include dialog.xml file

            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(
                    new ColorDrawable(Color.TRANSPARENT));

            dialog.setContentView(R.layout.text_custom_dialog);
            dialog.setCancelable(false);
            // Set dialog title

              et_view = (EditText) dialog.findViewById(R.id.et_view);


            // et_view.setText("" + txtHidden.getText().toString().trim());
               dialog.setTitle("Text Appearance");
              dialog.show();
            mSpinner_text_style = (Spinner) dialog
                    .findViewById(R.id.spinner_text_style);
            mIbtn_color_text = (ImageButton) dialog
                    .findViewById(R.id.ibtn_color_text);

            TextAdapter adapter = new TextAdapter(MainActivity.this,
                    R.layout.spinner_row, style);
            mSpinner_text_style.setAdapter(adapter);

            mSpinner_text_style
                    .setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> arg0,
                                                   View arg1, int arg2, long arg3) {
                            // TODO Auto-generated method stub
                            photoEditorApplication.setPosition(arg2);
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {
                            // TODO Auto-generated method stub

                        }
                    });

            mIbtn_color_text.setBackgroundColor(photoEditorApplication.getColor());

            mIbtn_color_text.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    showColorPickerDialogDemo();

                }
            });


            Button declineButton = (Button) dialog
                    .findViewById(R.id.btn_cancel);
            // if decline button is clicked, close the custom dialog
            declineButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // Close dialog
                    dialog.dismiss();
                }
            });

            Button Ok = (Button) dialog.findViewById(R.id.btn_ok);
            // if decline button is clicked, close the custom dialog
            Ok.setOnClickListener(new View.OnClickListener()
            {

                @Override
                public void onClick(View v)
                {
                    // Close dialog
                    txtHidden = null;

                   txtHidden = new TextView(MainActivity.this);

                    final FrameLayout.LayoutParams params =
                            new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                                    FrameLayout.LayoutParams.WRAP_CONTENT);
                    txtHidden.setLayoutParams(params);
                    txtHidden.setTextColor(photoEditorApplication.getColor());
                    Typeface face = Typeface.createFromAsset(getAssets(),
                            style[photoEditorApplication.getPosition()]);

                    txtHidden.setTypeface(face);
                    txtHidden.setTextSize(60);

                    String s = et_view.getText().toString().trim();
                    Log.e("et text", s);
                    txtHidden.setText(" " + s + " ");


                    if (txtHidden.getText().toString().trim().length() == 0) {
                        Snackbar snackbar = Snackbar.make(mRootLayout, "Please Enter Text", Snackbar.LENGTH_LONG);
                        snackbar.getView().setBackgroundColor(getResources().getColor(R.color.colorPrimary));
                        snackbar.show();
                    } else {


  //                            
              Toast.makeText(MainActivity.this,txtHidden.getText()+" 
          niravvvv",Toast.LENGTH_LONG).show();
                        txtHidden.setVisibility(View.INVISIBLE);
                        txtHidden.setDrawingCacheEnabled(false);
                        mainFrame.addView(txtHidden);


                        new CountDownTimer(1000, 1000) {
                            @Override
                            public void onTick(long millisUntilFinished) {

                            }

                            @Override
                            public void onFinish() {

                                txtHidden.setDrawingCacheEnabled(true);
                                txtHidden.buildDrawingCache();
                                sticker_view.setVisibility(View.VISIBLE);
                                sticker_view.setWaterMark(txtHidden.getDrawingCache(), null);

                                dialog.dismiss();
                            }
                        }.start();
                    }

                }
            });

            // ===========================================


        }
    });

2 个答案:

答案 0 :(得分:0)

下面有2个点击列表查看器

t1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(getBaseContext(), "Clicked", Toast.LENGTH_SHORT).show();
    }
});

t1.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(getBaseContext(), "Long Clicked", Toast.LENGTH_SHORT).show();
        return true;
    }
});

答案 1 :(得分:0)

in Stickerview class in onTouch() method long press case u have to call interface (which is in StickerView class) method , that interface u have to implment and override that methods in your Mainactivity