android 微信我的页面代码
时间: 2023-11-17 15:07:46 浏览: 39
以下是一个简单的Android微信“我的”页面的代码示例:
XML布局文件:
```
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/profile_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:background="@drawable/profile_placeholder"
android:contentDescription="@string/profile_image" />
<TextView
android:id="@+id/profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:text="@string/profile_name"
android:textColor="@color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/profile_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:text="@string/profile_email"
android:textColor="@color/dark_grey"
android:textSize="14sp" />
<Button
android:id="@+id/edit_profile_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/edit_profile_button"
android:background="@color/wechat_green"
android:textColor="@color/white" />
</LinearLayout>
```
Java代码:
```
public class MyProfileActivity extends AppCompatActivity {
private ImageView profileImage;
private TextView profileName;
private TextView profileEmail;
private Button editProfileButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_profile);
profileImage = findViewById(R.id.profile_image);
profileName = findViewById(R.id.profile_name);
profileEmail = findViewById(R.id.profile_email);
editProfileButton = findViewById(R.id.edit_profile_button);
// 设置头像和名称
profileImage.setImageResource(R.drawable.profile_image);
profileName.setText(getString(R.string.profile_name));
profileEmail.setText(getString(R.string.profile_email));
// 编辑资料按钮的点击事件处理
editProfileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 跳转到编辑资料页面
Intent intent = new Intent(MyProfileActivity.this, EditProfileActivity.class);
startActivity(intent);
}
});
}
}
```
上述代码中,我们使用一个LinearLayout布局来包含头像、名称、邮箱和编辑资料按钮。在Java代码中,我们获取了这些视图的引用,并在onCreate方法中设置了它们的显示内容和按钮的点击事件处理程序。当用户点击编辑资料按钮时,我们会跳转到编辑资料页面。