I want to declare a custom view, BUT I also want the home logo with up icon to appear on the left with its default functionality. How can I achieve to use both?
This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
You'll want to add android:fitsSystemWindows="true" to the parent layout of the Toolbar to ensure that the height of the activity is calculated correctly. When using the support library, make sure that you are importing android. support. v7.
To add actions to the action bar, create a new XML file in your project's res/menu/ directory. The app:showAsAction attribute specifies whether the action should be shown as a button on the app bar.
Best way is to use XML styles:
<style name="Theme.Main" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">@style/Widget.ActionBar</item>
</style>
<style name="Widget.ActionBar" parent="android:Widget.Holo.Light.ActionBar">
<item name="android:displayOptions">showHome|useLogo|showCustom</item>
<item name="android:customNavigationLayout">@layout/custom</item>
</style>
Then simply set this theme as either the application theme or activity them in AndroidManifest.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With