Actionlayout on Menuitem Does Nothing

actionlayout on menuitem does nothing

Try app:actionLayout="@layout/check" instead of android:actionLayout="@layout/check".

If you're using ActionbarSherlock or AppCompat, the android: namespace will not work for MenuItems. This is because these libraries use custom attributes that mimic the Android APIs since they did not exist in earlier versions of the framework.

menu Item not showing if actionLayout is set

As you have already defined app:actionLayout in your menu item of your actionbar_sync.xml menu file, the default android:icon attribute won't work. Therefore, the solution is to add your sync icon using an ImageView along with your ImageView with badge in your actionbar_badge_layout.xml file and remove android:icon attribute from your menu item.

actionbar_sync.xml

<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/action_sync"
android:title="Sync"
app:actionLayout="@layout/actionbar_badge_layout"
app:showAsAction="always"
/>
</menu>

actionbar_sync.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="?attr/actionButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:focusable="true"
>

<!-- Badge -->
<ImageView
android:id="@+id/img_badge_sync"
android:layout_width="12dp"
android:layout_height="12dp"
android:src="@drawable/badge_noty" />

<!-- Sync image -->
<ImageView
android:id="@+id/icon_sync"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/ic_sync" />

</FrameLayout>

Android action bar menu item with actionLayout not working properly

Try this code in your activity.

Be sure to properly set your

R.menu.menuidentifier

R.id.menuitemidentifier

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actionbarhelpmenu, menu);
final Menu m = menu;
final MenuItem item = menu.findItem(R.id.ActionConnection);
item.getActionView().setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
m.performIdentifierAction(item.getItemId(), 0);
}
});
return true;
}

onOptionsItemSelected in Menu is not clickable for item using actionLayout

override fun onCreateOptionsMenu(menu_: Menu): Boolean {
menu = menu_
menuInflater.inflate(R.menu.uppermenu, menu)
var cartMenuItem = menu!!.findItem(R.id.Cart)
cartMenuItem.actionView?.cart.setOnClickListener {
cartMenuItem.actionView?.cart_badge.text = "content update in the textview"
}
return true
}

The above snippet should perform onClick event for you

onOptionsItemSelected() not called when clicking on menu item which has an actionLayout set on it

Use this as shown in onOptionsItemSelected not called when using actionLayout (SherlockActionBar)

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.map_menu, menu);
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
if (item.getItemId() == R.id.menu_more) {
itemChooser = item.getActionView();
if (itemChooser != null) {
itemChooser.setOnClickListener(this);
}
}
}
return super.onCreateOptionsMenu(menu);
}


Related Topics



Leave a reply



Submit