kullanılmayan öğeleri kaldırın (sadece menü temasını uygulamak için).
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:theme="@style/AppTheme" />
sonra aşağıdaki gibi yeni menü öğeleri eklemek için getMenu
kullanın: gibi Yani, olacak!
Button btn1= (Button) findViewById(R.id.btn_test);
PopupMenu popup = new PopupMenu(yourFormName.this, btn1);
//Inflating the Popup using xml file
popup.getMenu().add("Menu1 Label");
popup.getMenu().add("Menu2 Label");
popup.getMenuInflater().inflate(R.menu.YourXMLFileName, popup.getMenu());
//registering popup with OnMenuItemClickListener
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
//---your menu item action goes here ....
Toast.makeText(DisplayTransactions.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
return true;
}
});
popup.show();//showing popup menu
Güzel tnx :) Eğer stilini nasıl ayarlanacağını biliyor musunuz Açılır menü?? – Mitch
Bunu özellikle nasıl yapacağımı bilmiyorum, hayır. [Bunlara] bakabilirsiniz (http://stackoverflow.com/questions/3142067/android-set-style-in-code) [related] (http://stackoverflow.com/questions/8369504/why-so- karmaşık-set-tarzı--mak-in-android-android) [sorular] (http://stackoverflow.com/questions/2016/249/how-to-programmatically-setting-style-attribute-in-a-view) . – kabuko
Başka kimse var mı? – Mitch