How to display menu item with icon and text in AppCompatActivity

@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.menu_patient_home_screen, menu); menu.add(0, 1, 1, menuIconWithText(getResources().getDrawable(R.mipmap.user_2), getResources().getString(R.string.action_profile))); menu.add(0, 2, 2, menuIconWithText(getResources().getDrawable(R.mipmap.add_user), getResources().getString(R.string.action_add_user))); menu.add(0, 3, 3, menuIconWithText(getResources().getDrawable(R.mipmap.switch_profile), getResources().getString(R.string.action_switch_profile))); menu.add(0, 4, 4, menuIconWithText(getResources().getDrawable(R.mipmap.logout), getResources().getString(R.string.action_sign_out))); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle … Read more

Change status bar color with AppCompat ActionBarActivity

I’m not sure I understand the problem. I you want to change the status bar color programmatically (and provided the device has Android 5.0) then you can use Window.setStatusBarColor(). It shouldn’t make a difference whether the activity is derived from Activity or ActionBarActivity. Just try doing: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = getWindow(); … Read more

Expand/Collapse Lollipop toolbar animation (Telegram app)

Edit : Since the release of the Android Design support library, there’s an easier solution. Check joaquin’s answer — Here’s how I did it, there probably are many other solutions but this one worked for me. First of all, you have to use a Toolbar with a transparent background. The expanding & collapsing Toolbar is … Read more

Add elevation/shadow on toolbar for pre-lollipop devices

For Android 5.0 and above : AppBarLayout automatically provides/gives shadow in the layout. You can also increase the elevation of the AppBarLayout by app:elevation=”4dp”. For Pre-Lollipop : You can use the following link: https://github.com/vipulasri/Toolbar-Elevation-Pre-Lollipop Note: Toolbar also supports elevation to it, using android:elevation=”4dp” New Update: In Appcompat v24.0.0, you can not set elevation to AppBarLayout … Read more

How to change Toolbar Navigation and Overflow Menu icons (appcompat v7)?

To change the navigation icon you can use: Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar); setSupportActionBar(toolbar); toolbar.setNavigationIcon(R.drawable.my_icon); To change the overflow icon you can use the method: toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.ic_my_menu); If you would like to change the color of the icons you can use: with a Material Components Theme (with a MaterialToolbar for example): <com.google.android.material.appbar.MaterialToolbar android:theme=”@style/MyThemeOverlay_Toolbar” …> <style … Read more

How can I align Android Toolbar menu/icons to the left like in Google Maps app?

After some struggling and digging in Android Toolbar code I managed to make it work. Basically, the idea is to add a new android.support.v7.widget.ActionMenuView as child of the Toolbar, set its gravity to top|start, and then add the menu to that action menu view in your Activity. Here is the code: my_toolbar.xml <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” … Read more

How to get Toolbar from fragment?

You need to cast your activity from getActivity() to AppCompatActivity first. Here’s an example: ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(); The reason you have to cast it is because getActivity() returns a FragmentActivity and you need an AppCompatActivity In Kotlin: (activity as AppCompatActivity).supportActionBar?.title = “My Title”

How to hide ToolBar when I scrolling content up?

you have to do many changes in your both layout. first use CoordinatorLayout in activity_main.XML like below(change theme as per your requirement). <?xml version=”1.0″ encoding=”utf-8″?> <android.support.design.widget.CoordinatorLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/main_content” android:layout_width=”match_parent” android:layout_height=”match_parent” android:fitsSystemWindows=”true”> <android.support.design.widget.AppBarLayout android:layout_width=”match_parent” android:layout_height=”wrap_content” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar”> <android.support.v7.widget.Toolbar android:id=”@+id/toolbar” android:layout_width=”match_parent” android:layout_height=”?attr/actionBarSize” android:background=”?attr/colorPrimary” android:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” app:layout_scrollFlags=”scroll|enterAlways” app:popupTheme=”@style/ThemeOverlay.AppCompat.Light” /> </android.support.design.widget.AppBarLayout> <include layout=”@layout/content_main” /> </android.support.design.widget.CoordinatorLayout> in content_main.XML use android.support.v4.widget.NestedScrollView instead … Read more

tech