android-actionbar

getSupportActionBar() NullPointerException

青春壹個敷衍的年華 提交于 2019-12-07 21:52:30
问题 In onCreate() method of activity I have this code for ToolBar : toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); My IDE warms me that getSupportActionBar().setDisplayHomeAsUpEnabled(true); may produce NullPointerException . My question is should I ignore it and how can I fix it anyway? 回答1: The IDE warns you about a potential NullPointerException because there are many cases where the app could throw one. For

Change the pressed color of action bar item of Lollipop action bar

夙愿已清 提交于 2019-12-07 20:28:37
问题 I am using AppCompat and have successfully implemented the new action bar that rolled out with lollipop. The only problem is the pressed background color of the action items. I want to show a different background color for the action item when pressed. Any idea how it can be done? 回答1: You have a couple of options. But first, some background: The action items in AppCompat use theme attribute ?attr/actionBarItemBackground (see res/values/styles_base.xml) which is set to ?attr

Switch button not showing up in ActionBar?

别等时光非礼了梦想. 提交于 2019-12-07 20:17:04
问题 I have a Switch that I placed into my ActionBar, but it doesn't seem to show up and I don't see why. This was my attempt: create_post_menu.xml <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context=".CreatePost"> <item android:id="@+id/toggle_test" android:title="" app:showAsAction="ifRoom" android:orderInCategory="1" android

contextual action bar padding in Android

↘锁芯ラ 提交于 2019-12-07 19:39:42
问题 I want to use contextual action bar in my app. When I start action mode, There are padding between default actionbar and contextual actionbar as shown in image 2. How can I avoid this padding ? for start action mode startSupportActionMode(modeCallBack); callback method : private ActionMode.Callback modeCallBack = new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.driver

saving fragment state actionbar tab

社会主义新天地 提交于 2019-12-07 16:21:35
问题 I am building an app that consists of actionbar with tabs, and each tab consists of a fragment. One of the fragments has data that need to be loaded. So I want the data to be loaded only the first time. When the user changes the tabs and goes back to the one containing that fragment, doesn't wait for the data to be loaded again. I assume I have to use some kind of saving the data so that it can be used the next time the user goes back to that particular fragment. But I just do not know what

ActionBar Up button: go to previous Activity with prev fragment

依然范特西╮ 提交于 2019-12-07 15:35:35
I need your help regarding my application flow. MainActivity (with Navigation Drawer) -- Fragment A -- Fragment B -- Fragment C (articles list view) ArticleActivity -- Fragment D (article detail view) Fragment C ( MainActivity ) displays a list of items ( ListView ). Selecting an item leads to fragment D (handle by ArticleActivity ) which presents that item in more detail. Fragment D displays a "Up" button that should allow the user to returns to previous screen (the detail view). The problem is that when the "Up" button is pressed the previous activity is displayed but not the previous

Galaxy S4 SupportActionBar covers whole screen in ActionMode

强颜欢笑 提交于 2019-12-07 15:26:36
问题 The Samsung Galaxy S4 shows a very weird behavior when going into ACtionMode on my app which is using SupportActionBar from Support-v7. Has anyone an idea how to fix this? I guess the issue comes from Samsung custom Android-Rom. 回答1: I solved this changing the parent of my custom actionmode theme from: <style name="MyApp.Widget.ActionMode" parent="@style/Widget.AppCompat.ActionMode"> to: <style name="Apo.Widget.ActionMode" parent="@style/Widget.AppCompat.Light.ActionMode.Inverse"> 回答2: For

android: menu item click event from fragment

一笑奈何 提交于 2019-12-07 15:07:03
问题 I have an application with actionbar. And there is menu inflated by the mainactivity. I want to intercept the click event inside the fragment but I don't know how? Can you help me please? MainActivity @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.home, menu); } home.xml <menu> <item android:id="@+id/action_refresh" android:title="@string/menu_refresh"/> </menu> And I want to refresh the list in the fragment 回答1: If you want to capture the click on

Forcing Overflow menu button on Android

安稳与你 提交于 2019-12-07 14:37:51
问题 I am developing an application for Android 4.0.3. I have multiple fragments and I have one menu item displayed on each of them. I want to have an overflow menu button that will have 2 menu items. How do I force the appearance of the overflow menu and add menu items to it ? I am adding menu items by calling the onCreateOptionsMenu function in each fragment. Any and all help would be appreciated. Thanks! 回答1: To force into the overflow menu do this: @Override public boolean onCreateOptionsMenu

How to fully mimic Action item view in the toolbar, for a customized one?

情到浓时终转凉″ 提交于 2019-12-07 13:44:42
问题 Background I have an action item that's not quite standard. It has its own layout, because I've failed to create a nice Drawable for it (written about it here). Basically, it's just a TextView with a background that wraps its short text that it shows. The problem Sadly I can't find a way of fully mimic it to look like normal ones: The ripple effect (and probably the simple clicking effect on older versions too) doesn't have the same color and size. There isn't a toast for when I long click on