ManuelPeinado / FadingActionBar

Android library implementing a fading effect for the action bar, similar to the one found in the Play Music app
Apache License 2.0
2.87k stars 677 forks source link

Getting error at initActionBar #97

Open sgkhode opened 9 years ago

sgkhode commented 9 years ago

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 commented 9 years ago

+1

JKMirko commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

screen

@JKMirko was yours doing similar?

JKMirko commented 9 years ago

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 commented 9 years ago

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

leef3 commented 9 years ago

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 commented 9 years ago

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

Anyone planning to fix this ?