How to change option menu icon in the action bar?

The following lines should be updated in app -> main -> res -> values -> Styles.xml <!– Application theme. –> <style name=”AppTheme” parent=”AppBaseTheme”> <!– All customizations that are NOT specific to a particular API-level can go here. –> <item name=”android:actionOverflowButtonStyle”>@style/MyActionButtonOverflow</item> </style> <!– Style to replace actionbar overflow icon. set item ‘android:actionOverflowButtonStyle’ in AppTheme –> <style … Read more

Android – Correct use of invalidateOptionsMenu()

invalidateOptionsMenu() is used to say Android, that contents of menu have changed, and menu should be redrawn. For example, you click a button which adds another menu item at runtime, or hides menu items group. In this case you should call invalidateOptionsMenu(), so that the system could redraw it on UI. This method is a … Read more

Item with app:showAsAction not showing

Things you should always check when you want to use action bar are 1) Extend ActionBarActivity instead of Activity public class MainMenu extends ActionBarActivity{ 2) Have the right style selected as defined at manifest Manifest <application android:icon=”@drawable/ic_launcher” android:label=”@string/app_name” android:theme=”@style/AppTheme” > Style <style name=”AppTheme” parent=”Theme.AppCompat.Light.DarkActionBar”> </style> 3) Select the right title for showAsAction <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:**yourapp**=”http://schemas.android.com/apk/res-auto” … Read more

How can I dynamically create menu items?

How to Dynamically Add Menu Items to an Android Activity public class yourActivity extends Activity { … private static final int MENU_ADD = Menu.FIRST; private static final int MENU_LIST = MENU.FIRST + 1; private static final int MENU_REFRESH = MENU.FIRST + 2; private static final int MENU_LOGIN = MENU.FIRST + 3; /** * Use if … Read more

Android custom dropdown/popup menu

Update: To create a popup menu in android with Kotlin refer my answer here. To create a popup menu in android with Java: Create a layout file activity_main.xml under res/layout directory which contains only one button. Filename: activity_main.xml <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:paddingBottom=”@dimen/activity_vertical_margin” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” tools:context=”.MainActivity” > <Button android:id=”@+id/button1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentLeft=”true” android:layout_alignParentTop=”true” … Read more

tech