简体   繁体   中英

Android AppCompat Actionbar customization

Im a little torn on appcompat at the moment. While it seems to be praised as an all in one answer, documentation seems really weak and im kind of lost on how to do a lot of things on it. What im ultimately trying to do is remove the Title on the actionbar, add buttons with custom icons (I have managed this one) and add a sliding side bar. I have been away from Android for a while now. I had started by opening up Android Studio and going with the Actionbar with Sidebar template. Seemed like the correct thing to do. As soon as I open up the activity class, I see that ActionBarActiivty has been deprecated. Ok, so I switch that out with AppCompatActivity.... Well now it wont run, get a stack trace saying it cannot be cast. On top of that it seems you cannot access the actionbar through code anymore either. YOu used to simply be able to grab the actionbar and call hide(). Here is some snippets for what I have tried

    <?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
        parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
        parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:displayOptions"></item>
    </style>
</resources>

Tried that to remove the title from the actionbar as suggested on another question. Is there a api reference page that has a list of all the item names that you can call and what they do?

So the reason you can't access the actionbar anymore is because you are not using it. These helped me out a lot when it came to learning appcompatactivity.

http://blog.xamarin.com/android-tips-hello-toolbar-goodbye-action-bar/

http://blog.xamarin.com/android-tips-hello-appcompatactivity-goodbye-actionbaractivity/

Also to remove the title, it's as simple as calling setTitle(null) in onCreate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM