Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error at initActionBar #97

Open
sgkhode opened this issue Dec 24, 2014 · 8 comments
Open

Getting error at initActionBar #97

sgkhode opened this issue Dec 24, 2014 · 8 comments

Comments

@sgkhode
Copy link

sgkhode commented Dec 24, 2014

Hello,
Here is my code, but I am getting error at line initActionBar
package com.krishinomy.farmweather;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.manuelpeinado.fadingactionbar.FadingActionBarHelper;

public class WeatherDetailsActivity extends ActionBarActivity
{

@Override
protected void onCreate( Bundle savedInstanceState )
{
    super.onCreate(savedInstanceState);

    FadingActionBarHelper helper = new FadingActionBarHelper().actionBarBackground(R.drawable.ab_background)
                    .headerLayout(R.layout.weather_detail_header)
                    .contentLayout(R.layout.weather_detail_content)
                    .headerOverlayLayout(R.layout.weather_detail_header_overlay);
    setContentView(helper.createView(this));
    helper.initActionBar(this);
    ListView listView = (ListView) findViewById(android.R.id.list);
    String[] items = loadItems();
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
    listView.setAdapter(adapter);
}

private String[] loadItems()
{

    String[] countries = new String[] { "String", "String" };
    return countries;
}

@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_weather_details, 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;
    }

    return super.onOptionsItemSelected(item);
}

}

can anyone guide me what could be issue?

Thanks

@phillwiggins
Copy link

+1

@JKMirko
Copy link

JKMirko commented Jan 21, 2015

I had the same problem and I think it's because ActionBarActivity returns null in method getActionBar().

You should try using this class instead of FadingActionBarHelper:

package com.example.custom;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

import com.manuelpeinado.fadingactionbar.FadingActionBarHelperBase;

public class MyFadingActionBarHelper extends FadingActionBarHelperBase {

    private ActionBar mActionBar;

    @Override
    protected int getActionBarHeight() {
        return mActionBar.getHeight();
    }

    @Override
    protected boolean isActionBarNull() {
        return mActionBar == null;
    }

    @Override
    protected void setActionBarBackgroundDrawable(Drawable drawable) {
        mActionBar.setBackgroundDrawable(drawable);
    }

    @Override
    public void initActionBar(Activity activity) {
        mActionBar = ((ActionBarActivity) activity).getSupportActionBar();
        super.initActionBar(activity);
    }
}

Notice that MyFadingActionBarHelper is using android.support.v7.app.ActionBar, where FadingActionBarHelper is using android.app.ActionBar as seen here.

Hope this helps! :)

@phillwiggins
Copy link

Hey thanks, it's partially worked. I've managed to get it within an activity but I still to mess around with Activity Bar colours. Really appreciate that!

@phillwiggins
Copy link

screen

@JKMirko was yours doing similar?

@JKMirko
Copy link

JKMirko commented Jan 21, 2015

Take a look at the links below. I think this could be a solution because it seems you didn't make your ActionBar transparent.

themes
styles

Here you can find themes and styles which make ActionBar transparent. Check out AndroidManifest.xml to see how these themes are applied.

Hope this helps! :)

@arkangelx
Copy link

I am trying to add some text to header but the headerOverlayLayout doesn't work. Has anyone done this?

@leef3
Copy link

leef3 commented Aug 8, 2015

I had the same issue and just solved it. I was using FadingActionBarHelper without the proper themes, styles, and manifest declarations.

You should make sure you Android Manifest uses
android:theme="@style/AppTheme.TranslucentActionBar"
and you have the styles.xml and themes.xml included in your project (in the sample)

@Arpan-Patel
Copy link

JKMirko's Jan 21 dated solution works fine. Thanks.
Btw, replace ActionBarActivity with AppCompatActivity to get it to work.

Anyone planning to fix this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants