Contextual Overlay stacking on top of toolbar - android

I have read about every answer on this and still can't seem to make it work. When I call startSupportActionMode, the action mode menu is stacked on top of the toolbar instead of replacing it. This graphic is from another user that was having the same issue.
Most of the other questions were resolved by using windowActionModeOverlay in the styles. This doesn't seem to be working for me. I'm also sure I'm importing the correction action mode.
(import android.support.v7.view.ActionMode;
)
My situation is a little different. My main activity is a AppCompatActivity. I load different fragments based on choices made from a navigation drawer. The actionbar is changed based on the navigation item selected.
This code all worked before I changed over to appCompat-v7. I am trying to convert to the new material design and am therefor replacing the base actionbar with a toolbar. Here are some code snippets:
Manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name="com.acme.common.MINApplication"
android:largeHeap="true">
<activity android:name="com.acme.common.MINMainActivity"
android:theme="#style/AppTheme"
android:configChanges="orientation|screenSize|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Styles:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/ColorPrimary</item>
<!-- Support library compatibility -->
<item name="colorPrimary">#color/ColorPrimary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/ColorPrimaryDark</item>
<!-- Support library compatibility -->
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:windowActionModeOverlay">true</item>
</style>
Main Activity:
public class MINMainActivity extends AppCompatActivity
{
private final String TAG = ((Object) this).getClass().getSimpleName();
private View mMainView;
// New Toolbar and Navigation View
public Toolbar toolbar;
public RecyclerView recyclerView;
private MINPageAdapter adapter;
private RecyclerView.LayoutManager layoutManager;
public DrawerLayout drawerLayout;
public android.support.v7.app.ActionBarDrawerToggle drawerToggle;
volatile public boolean isDrawerOpen = false;
private Menu mMenu;
#Override
public void onCreate(Bundle savedInstanceState)
{
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS | Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
// Inflate main view
mMainView = getLayoutInflater().inflate(R.layout.material_design_drawer_layout, null);
setContentView(mMainView);
sharedInstance = this;
// Setup New Toolbar implementation
setupToolbar();
// Setup Recycler Adapter
setupAdapter();
// Setup Navigation View
initNavigationDrawer();
// Show startup screen/fragment
showStartupScreen();
// Color components based on json settings
setCustomAttributes();
init();
}
Fragment:
public class MINPageTypeGridFragment extends Fragment
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setRetainInstance(true);
setHasOptionsMenu(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Inflate view
gridView = (StickyGridHeadersGridView)inflater.inflate(R.layout.page_gridview_fragment, container, false);
// Set up specific controls/views
initializeGridView(inflater, container);
...
return gridView;
}
#Override
public void onResume()
{
ActionBar actionBar = MINMainActivity.getSharedInstance().getSupportActionBar();
if(actionBar != null)
{
actionBar.show();
actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP |
ActionBar.DISPLAY_SHOW_HOME |
ActionBar.DISPLAY_USE_LOGO |
ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setTitle(pageDefinition.pageName);
}
...
super.onResume();
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
int count = 0;
...
freezeGridView();
mActionMode = MINMainActivity.getSharedInstance().startSupportActionMode(mActionModeCallback);
...
return super.onOptionsItemSelected(item);
}
public ActionMode.Callback mActionModeCallback = new ActionMode.Callback()
{
#Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu)
{
MenuItem shareMenuItem;
...
actionMode.getMenuInflater().inflate(R.menu.gridview_edit_menu, menu);
shareMenuItem = menu.findItem(R.id.MenuItemShare);
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareMenuItem);
if(mShareActionProvider != null)
{
mShareActionProvider.setShareIntent(Share(null));
mShareActionProvider.setOnShareTargetSelectedListener(new ShareActionProvider.OnShareTargetSelectedListener()
{
#Override
public boolean onShareTargetSelected(ShareActionProvider shareActionProvider, Intent intent)
{
if(mActionMode != null)
{
currentMode = MODE_STANDARD;
clearSelectedItems();
mActionMode.finish();
mActionMode = null;
}
return false;
}
});
...
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu)
{
return false;
}
#Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem)
{
switch(menuItem.getItemId())
{
case R.id.MenuItemEdit:
launchAlbumItemDetails(MINPageTypeGridFragment.this, currentAlbumItem, pageDefinition.pageConfigFileName);
return true;
case R.id.MenuItemDelete:
deleteItem(MINPageTypeGridFragment.this, currentAlbum, currentAlbumItem);
return true;
default:
return false;
}
}
#Override
public void onDestroyActionMode(ActionMode actionMode)
{
clearSelectedItems();
}
}
I'm sure that I'm missing something obvious but I'm out of ideas.

You should remove 'duplicate' definition: android:windowActionModeOverlay -> windowActionModeOverlay; android:colorPrimary -> colorPrimary and so on. This is an example that should work:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionModeOverlay">true</item>
<item name="colorControlNormal">#color/appColorControlNormal</item>
<item name="colorControlHighlight">#color/appColorControlHighlight</item>
<item name="colorControlActivated">#color/appColorControlActivated</item>
<item name="colorPrimary">#color/appColorPrimary</item>
<item name="colorPrimaryDark">#color/appColorPrimaryDark</item>
<item name="colorAccent">#color/appColorAccent</item>
</style>

Be sure to set the toolbar as current actionbar (maybe your method setupToolbar already do this):
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
After that, change your code and start the action mode directly from the toolbar reference:
toolbar.startActionMode(mActionModeCallback)
Let us know if this fix your problem.

Related

Put an icon in the Toolbar

I have a toolbar that has only the menu icon, and it is setted programmatically, like this:
myToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(myToolbar);
myToolbar.setTitleTextColor(Color.BLACK);
ActionBar ab = getSupportActionBar();
ab.setHomeAsUpIndicator(R.drawable.menu);
ab.setDisplayHomeAsUpEnabled(true);
Now, i would like to have another icon in the toolbar, and associate to it my src image and onClick Method. As you can see I don't have a xml menu file, and i also don't want to set a default android icon, so how can I perform this?
The main purpose of Toolbar is using custom layout!
You can add whatever UI elements, like button, to your Toolbar and find them in code.
You can set a CustomView to the ActionBar by supplying a layout file or View object. In that custom view you can do whatever you want.
Here is how you can set custom view to the action bar
protected void setCustomActionBarTitle(String title) {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.layout_action_bar_title);
TextView titleView = (TextView) actionBar.getCustomView().findViewById(R.id.action_bar_title);
titleView.setText(title);
ImageView customIconImageView = (ImageView) actionBar.getCustomView().findViewById(R.id.custom_icon);
customIconImageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// call my method on the activity
}
});
ImageView imageView = (ImageView) actionBar.getCustomView().findViewById(R.id.up_icon);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
}
}
You're going to have to use a separate xml file to setup your menu and define any extra buttons (item) in there. Here is sample menu file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- "Mark Favorite", should appear as action button if possible -->
<item
android:id="#+id/action_favorite"
android:icon="#drawable/ic_favorite_black_48dp"
android:title="#string/action_favorite"
app:showAsAction="ifRoom"/>
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
app:showAsAction="never"/>
</menu>
Add the icon which you want in your menu --> menu_main.xml
<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=".ui.MainActivity">
<item
android:id="#+id/action_scan"
android:icon="#drawable/camera_icon"
android:orderInCategory="100"
android:title="#string/action_scan"
android:visible="true"
app:showAsAction="always" />
and in your activity
#Override
public boolean onCreateOptionsMenu(Menu menu) {
/* Inflate the menu; this adds items to the action bar if it is present. */
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
This code is work for me,
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.app_name);
toolbar.setTitleTextColor(getResources().getColor(R.color.colorWhite));
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
Use this to add your icons into your tool bar. Override these methods and use the code in your project..
#Override
public boolean onCreateOptionsMenu(Menu menu) {
this.menu = menu;
getMenuInflater().inflate(R.menu.menu_dashboard, menu);
menu.getItem(0).setIcon(getResources().getDrawable(R.drawable.ic_about));
menu.getItem(1).setIcon(getResources().getDrawable(R.drawable.street_view_icon));
return true;
}
//Notification Icon
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_notify_found:
Intent aboutIntent=new Intent(DashboardActivity.this, HomeAboutActivity.class);
startActivity(aboutIntent);
case R.id.action_notify_found1:
Intent ARStreetviewintent = new Intent(DashboardActivity.this, ARStreetviewActivity.class);
startActivity(new Intent(DashboardActivity.this, StreetviewActivity.class));
default:
return super.onOptionsItemSelected(item);
}
}
Menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- Notification Found -->
<item android:id="#+id/action_notify_found"
android:icon="#drawable/about"
android:title="About"
app:showAsAction="ifRoom"
/>
<!-- Notification Found -->
<item android:id="#+id/action_notify_found1"
android:icon="#drawable/street_view_icon"
android:title="StreetView"
app:showAsAction="ifRoom"
/>

Adding Action Icons to toolbar in an activity that extends ListActivity

I am trying to add action icons to my toolbar but in vain. I have followed all the suggestion from this thread.
Maybe the problem is that my Activity doesn't extend ActionBarActivity directly because it already extends ListActivity as follows:
public class ShopsCatalogueActivity extends ListActivity {
private Toolbar toolbar; // Declaring the Toolbar Object
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//using delegates because this activity already extends ListActivity and we want to add toolbar
AppCompatCallback callback = new AppCompatCallback() {
#Override
public void onSupportActionModeStarted(ActionMode actionMode) {
}
#Override
public void onSupportActionModeFinished(ActionMode actionMode) {
}
#Nullable
#Override
public ActionMode onWindowStartingSupportActionMode(ActionMode.Callback callback) {
return null;
}
};
AppCompatDelegate delegate = AppCompatDelegate.create(this, callback);
delegate.onCreate(savedInstanceState);
//get the layout
delegate.setContentView(R.layout.activity_shops_catalogue);
//adding toolbar following material design approach
toolbar= (Toolbar) findViewById(R.id.tool_bar); // Attaching the layout to the toolbar object
delegate.setSupportActionBar(toolbar);
...
}
here is my menu.xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:MyOwnAppNameSpace="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
MyOwnAppNameSpace:showAsAction="never" />
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_search"
android:orderInCategory="200"
android:title="Search"
MyOwnAppNameSpace:showAsAction="always"></item>
<item
android:id="#+id/action_user"
android:icon="#drawable/ic_user"
android:orderInCategory="300"
android:title="User"
MyOwnAppNameSpace:showAsAction="ifRoom"></item>
</menu>
In the Activity:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.shops_catalogue_toolbar_menu, menu);
return true;
}
In build.gradle I am using:
compile 'com.android.support:appcompat-v7:22.2.0'
One approach you could use is to use a FragmentActivity as your base activity then have it load in a ListFragment. In the list fragment you can simply add this line in the onCreate method:
getActivity().getActionBar().setIcon(R.drawable.ic_main);
However Budius is right you should use a RecyclerView, its a new android class which simplifies the old viewholder pattern.
Android List and Card Guide ,
RecyclerView Android Doc

Android Material Design navigation drawer menu icon chage

I implemented a Material Design nav drawer using this example. I customize it according to my theme. Everything is working perfectly. Just the last thing I want to customize it's menu icon. I googled it, but have not find any good solution. I want to change its color if possible , or add a custom drawable. Any solution on idea. Thanks in advance
This is my Application theme which i set in menifest
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/textColorPrimary</item>
<item name="android:windowBackground">#color/windowBackground</item>
</style>
And this is my toolbar style
<
style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorPrimary">#color/headerColor</item>
<item name="android:iconPreview">#drawable/ic_launcher</item>
<item name="actionMenuTextColor">#color/colorPrimaryDark</item>
<item name="android:textColorSecondary">#color/headerColor</item>
My Main activity code
public class Activity_Home extends ActionBarActivity implements FragmentDrawer.FragmentDrawerListener {
private static String TAG = Activity_Home.class.getSimpleName();
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_drawer);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
// display the first navigation drawer view on app launch
displayView(0);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity__main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
//
// if(id == R.id.action_search){
// Toast.makeText(getApplicationContext(), "Search action is selected!", Toast.LENGTH_SHORT).show();
// return true;
// }
return super.onOptionsItemSelected(item);
}
#Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}
private void displayView(int position) {
}
}
Add:
getSupportActionBar().setHomeAsUpIndicator(resId);
or
getSupportActionBar().setHomeAsUpIndicator(drawable);
to your Activity's onCreate
Found a sloution myself. It was pretty easy indeed. All you have to do is set a toolbar style. In your style primary color act as a toolbar title and textScondary color act as a menu icon color.
style name="GalaxyZooThemeToolbarDarkOverflow" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorPrimary">#color/headerColor</item>
<item name="android:iconPreview">#drawable/ic_launcher</item>
<item name="actionMenuTextColor">#color/colorPrimaryDark</item>
<item name="android:textColorSecondary">#color/headerColor</item>

colorPrimary and colorPrimaryDark are ignored within application theme

(Note: This is somewhat related to When using ActionMode, the status bar turns black on Lollipop so there might be some additional information there that I accidentally omitted from this question)
I have the following theme defined:
<style name="Material" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/app_green</item>
<item name="colorPrimaryDark">#color/app_green_dark</item>
<item name="android:textColorPrimary">#color/action_bar_text</item>
<item name="android:textColor">#color/secondary_text_color</item>
<item name="android:color">#color/secondary_text_color</item>
<item name="colorAccent">#color/app_green</item>
<item name="android:editTextColor">#color/secondary_text_color</item>
<item name="textHeaderMaxLines">#integer/text_header_max_lines</item>
<item name="trackAbstractMaxLines">#integer/track_abstract_max_lines</item>
<item name="activatableItemBackground">#drawable/activatable_item_background</item>
<!-- ActionMode Styles -->
<item name="android:windowActionModeOverlay">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="actionModeStyle">#style/Material.Widget.ActionMode</item>
<!-- Global UI Assignments -->
<item name="android:spinnerStyle">#style/Material.Widget.Spinner</item>
<item name="android:buttonStyle">#style/Material.Widget.Button</item>
<item name="android:checkboxStyle">#style/Material.Widget.Checkbox</item>
<item name="android:textAppearance">#android:style/TextAppearance</item>
<item name="android:popupWindowStyle">#style/Material.Window.Popup</item>
<!-- ViewPager -->
<item name="vpiCirclePageIndicatorStyle">#style/Material.Activity.Login.ViewPagerIndicator.CustomCircle</item>
<item name="buttonBarStyle">?android:buttonBarStyle</item>
<item name="buttonBarButtonStyle">?android:buttonBarButtonStyle</item>
<item name="indeterminateProgressStyle">?android:indeterminateProgressStyle</item>
<!-- API 14+ (compatibility) -->
<item name="listPreferredItemPaddingLeft">#dimen/compat_list_preferred_item_padding_left</item>
<item name="listPreferredItemPaddingRight">#dimen/compat_list_preferred_item_padding_right</item>
<item name="listPreferredItemHeightSmall">#dimen/compat_list_preferred_item_height_small</item>
</style>
I use this theme as follows:
<application
android:name=".MyApp"
android:icon="#drawable/icon"
android:logo="#null"
android:label="#string/app_name"
android:theme="#style/Material"
android:hardwareAccelerated="true"
android:allowBackup="true">
<activity
android:name=".ui.MainActivity"
android:label="#string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.DetailActivity"
android:label="Details"
android:theme="#style/Material.Activity" >
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable"/>
</activity>
</application>
All of my activities derive from NavigationDrawerActivity:
/**
* An {#link Activity} that supports a Navigation Drawer, which is a pull-out panel for navigation
* menus. This drawer is pulled out from the left side of the screen (right side on RTL devices).
*/
public class NavigationDrawerActivity extends ActionBarActivity
implements AdapterView.OnItemClickListener {
private static final String LOGTAG = NavigationDrawerActivity.class.getSimpleName();
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private LayoutInflater mInflater;
private NavigationDrawerItemAdapter mAdapter;
private ActionBarDrawerToggle mDrawerToggle;
private NavigationDrawerItem[] mNavigationDrawerItems;
private Toolbar mAppBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// We have to call super.setContentView() here because BaseActivity redefines setContentView(),
// and we don't want to use that.
super.setContentView(R.layout.navigation_drawer);
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
setupNavigationDrawer();
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch(id) {
case android.R.id.home:
return mDrawerToggle.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}
/**
* Toggles the state of the navigation drawer (i.e. closes it if it's open, and opens it if
* it's closed).
*/
public void toggleNavigationDrawer() {
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
closeNavigationDrawer();
} else {
openNavigationDrawer();
}
}
/**
* Opens the navigation drawer.
*/
public void openNavigationDrawer() {
mDrawerLayout.openDrawer(GravityCompat.START);
}
/**
* Closes the navigation drawer.
*/
public void closeNavigationDrawer() {
mDrawerLayout.closeDrawer(GravityCompat.START);
}
/**
* Initializes items specific to the navigation drawer.
*/
private void setupNavigationDrawer() {
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.wiw_green));
mAppBar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(mAppBar);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
mDrawerToggle = new ActionBarDrawerToggle(
this, /* Our context (Activity that hosts this drawer) */
mDrawerLayout, /* The DrawerLayout where the nav drawer will be drawn */
R.string.drawer_open, /* Description of "open drawer", for accessibility */
R.string.drawer_close /* Description of "close drawer", for accessibility */
) {
/**
* Called when a drawer has settled in a completely closed state.
*/
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
supportInvalidateOptionsMenu();
}
/**
* Called when a drawer has settled in a completely open state.
*/
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
supportInvalidateOptionsMenu();
}
};
mDrawerList = (ListView) mDrawerLayout.findViewById(R.id.drawer_list);
mNavigationDrawerItems = buildNavDrawerItemsList();
setupAdapter(mNavigationDrawerItems);
setupNavigationDrawerHeader();
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerList.setOnItemClickListener(this);
}
#Override
public void onItemClick(AdapterView<?> parent, View aView, int aPosition, long aId) {
// Code not relevant
}
/**
* Set the inner content view of this {#link NavigationDrawerActivity} to have a given layout.
*
* #param aLayoutId The id of the layout to load into the inner content view of this activity.
*/
public void setDrawerContent(int aLayoutId) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup root = (ViewGroup)findViewById(R.id.drawer_content);
inflater.inflate(aLayoutId, root);
}
}
In NavigationDrawerActivity, I actually have to manually set the status bar background color (see the second line of setupNavigationDrawer()), rather than having it automatically set from colorPrimaryDark on Android 5.0 devices. Further, changing the color in either colorPrimary or colorPrimaryDark does not change the color of the status bar (although, this could be an effect from having windowTranslucentStatus set to true) or the Toolbar background color.
I'm wondering what I can do to alleviate this problem, as I think it's causing other problems in my Material-esque theme.
The documentation that you cite is referring to the native Android 5.0 Theme.Material. appcompat-v7 does not appear to be automatically applying any colors to the status bar, at least at this time.
So, for example, this sample project, when run on an Android 5.0 device, gets the status bar color, because it is using Theme.Material. This port of the same sample project to use appcompat-v7 does not. This revised version of the same sample that uses appcompat-v7 and specifically requests the status bar color change gets the color.

Nothing is showing up in the action bar

I have made a custom theme for my app which uses action bar.Now when i run my app the actionbar is visible but button in it is not visible.I dont know what went wrong.
The button is visible when i click on menu button (the 3 hardware button) but not displaying on the action bar
Style.Xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="TripLoggerTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/TripLoggerActionBar</item>
<!--<item name="android:homeAsUpIndicator">#drawable/test</item>-->
</style>
<!--use to style the actionbar-->
<style name="TripLoggerActionBar" parent="android:Widget.ActionBar">
<item name="android:background">#6e784c</item>
<item name="android:showAsAction">ifRoom|always|collapseActionView|never|withText</item>
<item name="android:displayOptions">homeAsUp|showHome|showTitle</item>
</style>
Menu.Xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/images"
app:showAsAction="always" />
</menu>
Code
public class MainActivity extends Activity {
private int[] images = {R.drawable.images, R.drawable.images_2, R.drawable.images_1, R.drawable.images_4, R.drawable.images, R.drawable.images_2};
private GridView gridView;
private LinearLayout linearLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.base_activity);
linearLayout = (LinearLayout) findViewById(R.id.root);
getActionBar();
// gridView = (GridView) findViewById(R.id.grid);
// gridView.setAdapter(new CustomAdapter(MainActivity.this, images));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
linearLayout.setVisibility(View.VISIBLE);
break;
}
return true;
}
As the screenshots shows,when i click on the 3 dots from below test is visible but it should be visible on the top where i have marked a cross
I tried finding out what could be the problem but all in vain.
I believe what you are experiencing is the standard Android behaviour. You may want to read the following text on the official docs on Action Overflow:
The overflow icon only appears on phones that have no menu hardware keys. Phones with menu keys display the action overflow when the user presses the key.
First, from snapshot, it seems that you are testing in emulator. Check if same happens on the device.

Categories

Resources