0

我正在开发贴纸应用程序,我可以在其中向 Stickerview 添加文本。我可以翻转、旋转和删除贴纸文本。现在我想在长按stickerText时编辑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();
                    }

                }
            });

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


        }
    });
4

2 回答 2

0

在 onTouch() 方法中的 Stickerview 类长按案例中,您必须调用接口(在 StickerView 类中)方法,该接口您必须在 Mainactivity 中实现并覆盖该方法

于 2018-02-03T08:06:24.637 回答
0

下面有 2 个点击 Listner 检查

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;
    }
});
于 2017-07-13T06:36:11.467 回答