private Toolbar tb_scroll;
private LinearLayout ll_context;
private RadioButton rb_talk;
private RadioButton rb_people;
private RadioButton rb_intent;
private RadioButton rb_circle;
private RadioGroup rg_button;
private NavigationView nv_scorll;
private DrawerLayout ll_drawer;
private ImageView headimage;
private TextView headname;
// 支持Toolbar
setSupportActionBar(tb_scroll);
// 设置联动
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, ll_drawer, tb_scroll, R.string.open, R.string.close);
// 添加连动
ll_drawer.addDrawerListener(actionBarDrawerToggle);
// 两者联动
actionBarDrawerToggle.syncState();
// 显示页面
// 色彩
nv_scorll.setItemIconTintList(null);
// 获取头部控件
View headerView = nv_scorll.getHeaderView(0);
// 获取头部图片控件
headimage = headerView.findViewById(R.id.iv_headimage);
//监听所有的头部按钮
headimage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 200);
}
});
// 获取头部文本控件
headname = headerView.findViewById(R.id.tv_headname);
headname.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 创建Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("头部");
View view = LayoutInflater.from(MainActivity.this).inflate(R.layout.layout_dialog, null);
final EditText tv_dialogname = view.findViewById(R.id.tv_dialogname);
builder.setView(view);
builder.setNegativeButton("取消", null);
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
headname.setText(tv_dialogname.getText().toString());
}
});
builder.show();
}
});
// 接收头部图片控件
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 200 & resultCode == RESULT_OK) {
Uri data1 = data.getData();
headimage.setImageURI(data1);
}
}
网友评论