Reputation:
I'm trying to show a menu when I clicked on an image. This is my full_screen_image.xml.I want to show when I clicked on @+id/photo_menu.
<ImageView
android:contentDescription="verter"
android:id="@+id/photo_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_more_vert_black_30dp"
android:tint="@android:color/white"
android:layout_marginTop="6dp"
android:layout_marginEnd="5dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"/>
</RelativeLayout>
This is menu_photo.xml.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/savePhoto"
android:title="Kaydet" />
<item android:id="@+id/sharePhoto"
android:title="Paylaş" />
</menu>
This is fullScreenImageActivity.java:
package com.example.ahmetbesli.circles;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
public class FullScreenImageActivity extends AppCompatActivity {
private ImageView arrowBack;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_screen_image);
arrowBack = (ImageView) findViewById(R.id.arrow_back);
arrowBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
ImageView fullScreenImageView = (ImageView) findViewById(R.id.fullScreenImageView);
Intent callingActivityIntent = getIntent();
if (callingActivityIntent != null) {
Uri imageUri = callingActivityIntent.getData();
if (imageUri != null && fullScreenImageView != null) {
Glide.with(this)
.load(imageUri)
.into(fullScreenImageView);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_photo,menu);
return true;
}
}
I couldn't understand how to connect that image and the menu. Thanks for your helps...
Upvotes: 0
Views: 953
Reputation: 680
Set a click listener to the image and in onclick method for that image view create any of the below 4 entities based on your requirement.
You have many options in your use case two of them would be.
1.Toast(only shows message no click events)
2.SnackBar (dismisses itself after some time, prefer this if you want user to respond quickly with some click action)
3.Using AlertDialog
4.Dialog Fragment
and in the both of the above methods(3 & 4) you can reference your menu items for click events or describe your own layout for dialog box and define buttons in those layouts for click events.
creation steps documentation: Android Dialogs
Dialog offers more functionalities and stays there till user closes it unlike toast which dismisses after some time if no action is taken.
Upvotes: 0