修改手机防盗名称,达到混淆
1、创建一个菜单项
LostFindActivity.java // 1、创建一个OptionsMenu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = new MenuInflater(this);
menuInflater.inflate(R.menu.menu_lost_find, menu);
return super.onCreateOptionsMenu(menu);
}\res\menu\menu_lost_find.xml <?xml version="1.0" encoding="utf-8"?>
<!-- 1、手机防盗更改名称弹出菜单UI -->
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/item_change_name"
android:title="更改手机防盗名称">
</item>
</menu> |
2、注册该条目的监听事件 LostFindActivity.java // 2、一个菜单项
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.item_change_name:
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("更改手机防盗名称");
final EditText et_newname = new EditText(this);
et_newname.setHint("请输入更改后的名称");
builder.setView(et_newname);
builder.setPositiveButton("更改", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String newName = et_newname.getText().toString();// 不判空,以后根据用户是否输入,来决定是否更名
SharedPreferences spf_newname = getSharedPreferences("config", MODE_PRIVATE);
Editor edit = spf_newname.edit();
edit.putString("newname", newName);
edit.commit();
}
});
builder.show();
break;
}
return super.onMenuItemSelected(featureId, item);
} |
3、HomeActivity.java SharedPreferences pdf_newnamw = getSharedPreferences("config", MODE_PRIVATE);
if (position==0) {
String newname = pdf_newnamw.getString("newname", "");
if (!TextUtils.isEmpty(newname)) {
tv_name.setText(newname);
}
}
|
|