EzDevInfo.com

android-actionbar interview questions

Top android-actionbar frequently asked interview questions

Can't Find Theme.AppCompat.Light for New Android ActionBar Support

I am trying to implement the new ActionBar support library that was released by Google a couple days ago. In the past, I have successfully implemented ActionBarSherlock without any issues using the same method listed on Google Developer's Support Library Setup page - using the guide on how to include the resources (which is similar to how ActionBarSherlock did it). I have the library project loaded in to my own project as a library as well.

I can tell the library is loading fine. When, instead of extending Activity on my MainActivity.java, I changed it to extend ActionBarActivity (as per Google's instructions), no errors occur - and it imports correctly.

I even tried bypassing the style.xml file and adding @style/Theme.AppCompat.Light directly in to the AndroidManifest.xml for both <application> and <activity> with android:theme="@style/ThemeAppCompat.Light" with all attempts resulting in the same error.

Now the issue is I cannot get it to change the theme, let alone even build without throwing an error. Below is the error I am receiving, followed by the style.xml file I changed to use the new theme.

I have moderate experience working with Android apps and am running Eclipse with the latest version of the Support Libraries and SDK compiling with API 18 (Android 4.3).

Error Received During Build

error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat.Light'. styles.xml /ActBarTest/res/values line 3 Android AAPT Problem

style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Theme.ProsoftStudio.ACTest" parent="@style/Theme.AppCompat.Light">
    </style>
</resources>

Any suggestions? This was never an issue with ActionBarSherlock. I want to work on using this new support library. It almost seems like the .jar is loading, but not the resources.


Source: (StackOverflow)

getActionBar() returns null

I'm having an odd problem. I am making an app with targetsdk 13.

In my main activity's onCreate method i call getActionBar() to setup my actionbar. This works fine when running on the Android 3.2 emulator, but when using Android 3.0 and 3.1 the getActionBar() method returns null.

I find this extremely odd, and i cannot see any reason why it would do so. Is this a bug with the emulators or is there something i need to do, in order to ensure that my application has an actionbar?

SOLUTION: I think I've found a solution for this problem. I wasn't using the setContentView to set a layout for the activity. Instead I was using fragmentTransaction.add(android.R.id.content, mFragment, mTag) to add a fragment to the activity. This worked fine in 3.2, but in earlier honeycomb versions the action bar is apparently not set if you don't use the setContentView in the onCreate() method. So I fixed it by using the setContentView() method in my onCreate() method and just supplying it with a layout that contained an empty FrameLayout. I can still use the fragmentTransaction.add(android.R.id.content, mFragment, mTag) method the same way as before.

It's not the prettiest fix, but it works.


Source: (StackOverflow)

Advertisements

Full Screen Theme for AppCompat

I would like to know how can I apply full screen theme ( no title bar + no actionbar ) to an activity. I am using AppCompat library from support package v7.

I've tried to applied android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to my specific activity but it crashed. I think it's because my application theme is like this.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

I also have tried this

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

which only hides title bar but not the action bar. My current workaround is that hiding the actionbar with

getSupportActionBar().hide();

Source: (StackOverflow)

Actionbar notification count badge like Google has

Is there a android-standard badge or method to show action-bar notification icon with a count like on Google examples?

count 3 on picture

If not, than what is the best way to make it?
I'm new to android, please help.


Source: (StackOverflow)

How to get the ActionBar height?

I am trying to get the height of the ActionBar (using Sherlock) every time an activity is created (specially to handle configuration changes on rotation where the ActionBar height might change).

For this I use the method ActionBar.getHeight() which works only when the ActionBar is shown.

When the first activity is created for the first time, I can call getHeight() in the onCreateOptionsMenu callback. But this method is not called after.

So my question is when can I call getHeight() and be assured that it doesn't return 0? Or if it is not possible, how can I set the height of the ActionBar ?


Source: (StackOverflow)

Android action bar not showing overflow

I have an action bar in my app with 3 items.

Only 2 can be displayed due to space issues, so I'd expect the first to be displayed and the rest to be displayed in the overflow. However in practice only the first 2 items are shown and there is no overflow detectable.

Here is the relevant code: list_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/menu_insert"
    android:icon="@android:drawable/ic_menu_add"
    android:title="@string/menu_insert" 
    android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/menu_call"
    android:icon="@android:drawable/ic_menu_call"
    android:title="@string/menu_call" 
    android:showAsAction="ifRoom|withText"/>
<item android:id="@+id/menu_agenda"
    android:icon="@android:drawable/ic_menu_agenda"
    android:title="@string/menu_agenda" 
    android:showAsAction="ifRoom|withText"/>
</menu>

Activity.java

public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater mi = getMenuInflater();
    mi.inflate(R.menu.list_menu, menu);
    return true;
}

Thanks!


Source: (StackOverflow)

How do I hide a menu item in the actionbar?

I have an action bar with a menuitem. How can I hide/show that menu item?

This is what I'm trying to do:

MenuItem item = (MenuItem) findViewById(R.id.addAction);
item.setVisible(false);
this.invalidateOptionsMenu();

Source: (StackOverflow)

Changing overflow icon in the action bar

Is it possible to change the overflow icon in the action bar? I have blue icons for all ActionBar items and I also want to change the overflow icon when it appears.


Source: (StackOverflow)

Android: How to change the ActionBar "Home" Icon to be something other than the app icon?

My application's main icon consists of two parts in one image: a logo and a few letters below it. This works well for the launcher icon for the app, but when the icon appears on the left edge of the ActionBar, the letters get cut off and it doesn't look good.

I would like to provide the ActionBar with a separate version of the icon, with only the "logo" part and not the letters beneath it, but so far have been coming up empty. I honestly can't find any answer to this, and I can't even find the question itself anywhere.


Source: (StackOverflow)

ActionBarActivity is deprecated (Android Studio) [duplicate]

This question already has an answer here:

Actually there is no problem. Project compiles and runs. But I can't understand what is mean strikeout class name (Android Studio tells that there is deprecated code is used)enter image description here. Can anybody explain?


Source: (StackOverflow)

Changing the background drawable of the searchview widget

I'm trying to change the drawable that sits in the Android actionbar searchview widget.

Currently it looks like this: enter image description here

but I need to change the blue background drawable to a red colour.

I've tried many things short of rolling my own search widget, but nothing seems to work.

Can somebody point me in the right direction to changing this?


Source: (StackOverflow)

Remove shadow below actionbar

I use actionbarsherlock. The piece of code below is responsible for changing it's background to a custom one.

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar">
    <item name="background">@drawable/actionbar_bg</item>
    <item name="android:background">@drawable/actionbar_bg</item>
    <...>  
</style>

<style name="Theme.MyApp" parent="@style/Theme.Sherlock.Light">
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <..>
</style>

And it works for actionbarsherlock (on versions below honeycomb). But in ICS I have a shadow below actionbar which I don't want. What is the style item to make it disappear?


Source: (StackOverflow)

How to add Action Bar from support library into PreferenceActivity?

Action Bar compatibility has been added into support library, revision 18. It now has ActionBarActivity class for creating activities with Action Bar on older versions of Android.

Is there any way to add Action Bar from support library into PreferenceActivity?

Previously I used ActionBarSherlock and it has SherlockPreferenceActivity.


Source: (StackOverflow)

Remove icon/logo from action bar on android

I've been trying to find some way of removing the icon/logo from the action bar but the only thing I've found after an hour of searching SO, Android's documentation and Google is how to remove the title bar in whole. That is not what I want. Only want to remove the icon/logo from the title bar.

Any one know how to accomplish this? Preferably I'd like to do this in XML.


Source: (StackOverflow)

How do I change the android actionbar title and icon

I'm trying to do some things on the Action Bar in Android

I've already added new items in the right side of the action bar

How can I change the left side of the action bar? I want to change the icon and the text, and I want to add a "Back Button" in the action bar for the other screens

Thanks in advance

Android Action Bar


Source: (StackOverflow)