简体   繁体   English

Android AppCompat Actionbar自定义

[英]Android AppCompat Actionbar customization

Im a little torn on appcompat at the moment. 我目前在appcompat上有点撕裂。 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. 我离开Android已有一段时间了。 I had started by opening up Android Studio and going with the Actionbar with Sidebar template. 我首先打开Android Studio,然后选择带有侧边栏模板的Actionbar。 Seemed like the correct thing to do. 似乎是正确的做法。 As soon as I open up the activity class, I see that ActionBarActiivty has been deprecated. 打开活动类后,立即看到ActionBarActiivty已被弃用。 Ok, so I switch that out with AppCompatActivity.... Well now it wont run, get a stack trace saying it cannot be cast. 好的,所以我用AppCompatActivity将其切换出来。...好了,它现在将无法运行,得到一个堆栈跟踪,表明它不能进行转换。 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(). YOu过去只是能够抓住操作栏并调用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? 是否有一个api参考页面,其中列出了您可以调用的所有项目名称以及它们的作用?

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-toolbar-goodbye-action-bar/

http://blog.xamarin.com/android-tips-hello-appcompatactivity-goodbye-actionbaractivity/ 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. 同样要删除标题,就像在onCreate中调用setTitle(null)一样简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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