Question

I'm implementing an ActionBar on my Activities. I'm trying to do this as a AndroidAnnotaions @EViewGroup component, but for some reason I cannot see the component in my Activities. The project compiles fine though.

My code is basically something like below

actionbar.xml

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="@dimen/action_bar_height"
  android:layout_width="match_parent"
  >

<ImageButton
  android:id="@+id/back"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:src="@drawable/back_button"
  />

<!-- Rest of the views omitted -->
</RelativeLayout>

ActionBar.java

@EViewGroup( R.layout.actionbar )
public class ActionBar extends RelativeLayout {

private Context mContext;

public ActionBar( Context aContext, AttributeSet aAttributeSet ) {
  super( aContext );
  mContext = aContext;
}
// @Click listener methods omitted

And this is how I'm using it in another layout XML

<jandy.android.ActionBar_
  android:id="@+id/actionbar"
  android:layout_width="match_parent"
  android:layout_height="@dimen/action_bar_height"
  />

According to the AA documentation this is all that is required. But as said, nothing is visible.

Thanks.

Était-ce utile?

La solution

I think you need to implement constructors with different parameters:

public CustomActionbarComponent(Context context) {
    super(context);
}

public CustomActionbarComponent(Context context, AttributeSet attrs) {
    super(context, attrs);  
}

public CustomActionbarComponent(Context context, AttributeSet attrs, int defStyle) {
    super(context);
}

Maybe the custom view created from xml use another constructor. That's the only difference with your code and my working custom actionbar.

Hope it helps!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top