圆形图像查看onclick监听器无法正常工作本网站上的每个解决方案都尝试但问题未解决我发布的代码请指导我谢谢
private CircleImageView setupImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup);
Toolbar setupToolbar = findViewById(R.id.setupToolbar);
setSupportActionBar(setupToolbar);
getSupportActionBar().setTitle("Account Setup");
setupImage = findViewById(R.id.setup_image);
setupImage.setClickable(true);
setupImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if(ContextCompat.checkSelfPermission(SetupActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED){
Toast.makeText(SetupActivity.this, "Permission Denied", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(SetupActivity.this, "You Already Have Permission", Toast.LENGTH_LONG).show();
}
}
}
});
}
}
答案 0 :(得分:0)
你可以尝试这个库:实现'de.hdodenhof:circleimageview:2.2.0'
activity_main.xml中
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:src="@mipmap/ic_launcher"
app:civ_border_color="#FF000000"
app:civ_border_width="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
main.java
CircleImageView circleImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
circleImageView = (CircleImageView) findViewById(R.id.profile_image);
circleImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "active", Toast.LENGTH_SHORT).show();
}
});
}