android 长按编辑界面,如何在Android Studio中长按EditText打开弹出窗口

我对你的问题的理解.

我的回答是

>长按“编辑文本”可以打开弹出窗口.

>将编辑文本文本复制到弹出窗口 – 编辑文本.

>按“确定”将弹出窗口编辑文本的文本复制回基本文本框.

附上代码供您参考

弹出窗口xml –

android:id="@+id/LinearLayout1"

android:layout_width="250dp"

android:layout_height="250dp"

android:background="#FFFFE0"

android:orientation="vertical"

android:paddingLeft="7dip"

android:paddingTop="7dip"

android:paddingRight="7dip"

android:paddingBottom="7dip">

android:id="@+id/edit_pop"

android:layout_width="match_parent"

android:layout_height="120dp"

android:ems="10"/>

android:id="@+id/btok"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="OK" />

主要活动 –

public class MainActivity extends Activity implements OnLongClickListener

{

EditText vedt=null,edPop;

Button btOk=null;

@Override

protected void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

vedt = (EditText) findViewById(R.id.editText1);

vedt.setOnLongClickListener(this);

}

@Override

public boolean onLongClick(View v)

{

LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);

View popupView = layoutInflater.inflate(R.layout.popup, null);

final PopupWindow popupWindow = new PopupWindow(popupView,android.view.ViewGroup.LayoutParams.WRAP_CONTENT,android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

edPop = (EditText)popupView.findViewById(R.id.edit_pop);

btOk = (Button)popupView.findViewById(R.id.btok);

edPop.requestFocus();

edPop.setText(vedt.getText().toString());

popupWindow.showAtLocation(popupView, Gravity.CENTER,5,5);

popupWindow.setOutsideTouchable(false);

popupWindow.setFocusable(true);

popupWindow.update();

btOk.setOnClickListener(new OnClickListener()

{

@Override

public void onClick(View v)

{

vedt.setText(edPop.getText().toString());

popupWindow.dismiss();

}

});

return false;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值