Android Studio Pop Menu With Icon
Main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/website"
android:title="@string/open_website"
android:icon="@drawable/publicc"/>
<item
android:id="@+id/ShowToast"
android:title="@string/open_commnet"
android:icon="@drawable/comment"/>
</menu>
Android Studio Design Animation
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".design5part3">
<ImageView
android:id="@+id/imageView35"
android:layout_width="168dp"
android:layout_height="214dp"
android:contentDescription="@string/todo51"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/downloadicon" />
<ImageView
android:id="@+id/ImageView_option"
android:layout_width="49dp"
android:layout_height="58dp"
android:contentDescription="@string/todo336"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/imageView35"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.379"
app:srcCompat="@drawable/more"
tools:ignore="VectorDrawableCompat" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="-2dp"
android:id="@+id/relativeLayout">
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-7177713247458792/8822662603"/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Android Studio Design Animation
Main_activity.xml
package com.designapp
import android.content.Intent
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.PopupMenu
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_design5play.*
class design5play : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_design5play)
ImageView_option.setOnClickListener{
val popupMenu= PopupMenu(this,it)
popupMenu.setOnMenuItemClickListener { item ->
when(item.itemId){
R.id.website -> {
val intent= Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com"))
startActivity(intent)
true
}
R.id.ShowToast ->{
Toast.makeText(this,"Showing Toast", Toast.LENGTH_LONG).show()
true
}
else -> false
}
}
popupMenu.inflate(R.menu.menu_main)
try{
val fieldMPopup = PopupMenu::class.java.getDeclaredField("mPopup")
fieldMPopup.isAccessible=true
val mPopup = fieldMPopup.get(popupMenu)
mPopup.javaClass
.getDeclaredMethod("setForceShowicon",Boolean::class.java)
.invoke(mPopup, true)
}catch (e:Exception){
Log.e("Main","Error Showing Menu Icon",e)
}finally {
}
popupMenu.show()
}
}
}
0 Response to "Android Studio Pop Menu With Icon"
Post a Comment