Question

How can I create the ActionBar with NavigationDrawer and CustomView. Like this: enter image description here

any ideas, suggestion and solution, please

Was it helpful?

Solution

The Following code shows how to change color and text, subtext color of ActionBar. Put this file in values/ folder and name it as theme.xml

<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@color/actionBarBG</item>
    <item name="android:backgroundSplit">@color/actionBarBG</item>
    <item name="android:subtitleTextStyle">@style/Theme.TitleTextStyle</item>
    <!-- Support library compatibility -->
    <item name="background">@color/actionBarBG</item>
</style>

<!-- STYLE TO CHAGE THE TITLE COLOR OF ACTION BAR -->
<style name="Theme.TitleTextStyle" parent="@android:style/Widget.TextView">
    <item name="android:textColor">#BDD6E0</item>
</style>

In you manifest apply to the activity as below in activity tag :

android:theme="@style/CustomActionBarTheme" 

For ActionItems in ActionBar you can use following code : eg. action_items.xml

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

    <item
        android:id="@+id/action_home"
        android:icon="@drawable/action_home"
        android:showAsAction="ifRoom"
        android:title="@string/home"
        yourapp:showAsAction="ifRoom"/>

    <item
        android:id="@+id/action_logout"
        android:icon="@drawable/action_logout"
        android:showAsAction="ifRoom"
        yourapp:showAsAction="ifRoom"
        android:title="@string/logout"/>

</menu>

Put this XML file in /Menu folder.

Then in activity:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.action_items, menu);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Take appropriate action for each action item click
        switch (item.getItemId()) {
        case R.id.action_home:
            Intent intent = new Intent(this, CustomerMenuActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            return true;
        case R.id.action_logout:
            // location found
            Intent intent2 = new Intent(this, LoginActivity.class);
            intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent2);
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top