Getting error at initActionBar
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
+1
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! :)
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!

@JKMirko was yours doing similar?
Take a look at the links below. I think this could be a solution because it seems you didn't make your ActionBar transparent.
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! :)
I am trying to add some text to header but the headerOverlayLayout doesn't work. Has anyone done this?
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
JKMirko's Jan 21 dated solution works fine. Thanks. Btw, replace ActionBarActivity with AppCompatActivity to get it to work.
Anyone planning to fix this ?