如何在android中编辑长点击监听器上的视图文本
我正在开发贴纸应用程序,在那里我可以添加文本到贴纸视图。我可以翻转、旋转和删除标签文本。现在,当我长时间单击stickerText时,我想编辑StickerView的文本。 下面是将文本标签添加到屏幕的代码如何在android中编辑长点击监听器上的视图文本,android,news-ticker,msstickerview,Android,News Ticker,Msstickerview,我正在开发贴纸应用程序,在那里我可以添加文本到贴纸视图。我可以翻转、旋转和删除标签文本。现在,当我长时间单击stickerText时,我想编辑StickerView的文本。 下面是将文本标签添加到屏幕的代码 imgText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { isEffectsVisib
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();
}
}
});
// ===========================================
}
});
imgText.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图v){
isEffectsVisible=isSttickerVisible=false;
设置可见性(View.GONE);
回收者效应。设置可见性(视图。消失);
recyclerView.setVisibility(View.GONE);
最终对话框=新对话框(MainActivity.this);
//包含dialog.xml文件
对话框.requestWindowFeature(窗口.FEATURE\u无\u标题);
dialog.getWindow().setBackgroundDrawable(
新型可着色(彩色透明);
setContentView(R.layout.text\u自定义\u对话框);
对话框。可设置可取消(false);
//设置对话框标题
et_view=(EditText)dialog.findViewById(R.id.et_view);
//et_view.setText(“+txtHidden.getText().toString().trim());
对话框.setTitle(“文本外观”);
dialog.show();
mSpinner\u text\u style=(微调器)对话框
.findviewbyd(R.id.spinner\u text\u样式);
mIbtn_颜色_文本=(图像按钮)对话框
.findviewbyd(R.id.ibtn\u颜色\u文本);
TextAdapter=新的TextAdapter(MainActivity.this,
R.layout.spinner(行、样式);
mSpinner_text_style.setAdapter(适配器);
mSpinner_文本_样式
.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView arg0,
视图arg1、整数arg2、长arg3){
//TODO自动生成的方法存根
Photoeditor应用程序设置位置(arg2);
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
});
mIbtn_color_text.setBackgroundColor(photoEditorApplication.getColor());
mIbtn\u color\u text.setOnClickListener(新视图.OnClickListener()的名称){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
showColorPickerDialogDemo();
}
});
按钮declineButton=(按钮)对话框
.findviewbyd(R.id.btn\u取消);
//如果单击了“拒绝”按钮,请关闭“自定义”对话框
declineButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//关闭对话框
dialog.dismise();
}
});
Button Ok=(Button)dialog.findViewById(R.id.btn_Ok);
//如果单击了“拒绝”按钮,请关闭“自定义”对话框
Ok.setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图v)
{
//关闭对话框
txtHidden=null;
txtHidden=新文本视图(MainActivity.this);
最终FrameLayout.LayoutParams参数=
新建FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_内容,
FrameLayout.LayoutParams.WRAP_内容);
txtHidden.setLayoutParams(参数);
setxtcolor(photoEditorApplication.getColor());
Typeface=Typeface.createFromAsset(getAssets(),
样式[photoEditorApplication.getPosition()];
txtHidden.setTypeface(面);
txtHidden.setTextSize(60);
字符串s=et_view.getText().toString().trim();
Log.e(“et文本”,s);
txtHidden.setText(“+s+”);
if(txtHidden.getText().toString().trim().length()==0){
Snackbar Snackbar=Snackbar.make(mRootLayout,“请输入文本”,Snackbar.LENGTH\u LONG);
snackbar.getView().setBackgroundColor(getResources().getColor(R.color.colorPrimary));
snackbar.show();
}否则{
//
Toast.makeText(MainActivity.this,txtHidden.getText()+)
Niravvv“,Toast.LENGTH_LONG).show();
txtHidden.setVisibility(View.INVISIBLE);
txtHidden.setDrawingCacheEnabled(false);
mainFrame.addView(txtHidden);
新的倒计时(10001000){
@凌驾
公共void onTick(长毫秒未完成){
}
@凌驾
公共无效onFinish(){
txtHidden.setDrawingCacheEnabled(true);
txtHidden.buildDrawingCache();
贴纸视图设置可见性(视图可见);
stacker_view.setWaterMark(txtHidden.getDrawingCache(),null);
dialog.dismise();
}
}.start();
}
}
});
// ===========================================
}
});
下面有两个单击列表器检查
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;
}
});
在第五章