FadingActionBar icon indicating copy to clipboard operation
FadingActionBar copied to clipboard

Getting error at initActionBar

Open sgkhode opened this issue 11 years ago • 8 comments

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

sgkhode avatar Dec 24 '14 09:12 sgkhode

+1

phillwiggins avatar Jan 15 '15 13:01 phillwiggins

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! :)

JKMirko avatar Jan 21 '15 10:01 JKMirko

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 avatar Jan 21 '15 16:01 phillwiggins

screen

@JKMirko was yours doing similar?

phillwiggins avatar Jan 21 '15 21:01 phillwiggins

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! :)

JKMirko avatar Jan 21 '15 22:01 JKMirko

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

arkangelx avatar Jul 24 '15 17:07 arkangelx

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)

leef3 avatar Aug 08 '15 15:08 leef3

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

Anyone planning to fix this ?

Arpan-Patel avatar Oct 13 '15 19:10 Arpan-Patel