2013-04-10 45 views
1

我在我的Activities上实现了一个ActionBar。我正在尝试将其作为AndroidAnnotaions @EViewGroup组件执行此操作,但出于某种原因,我无法在“活动”中看到该组件。该项目编译罚款,但。ViewGroup injection with AndroidAnnotation

我的代码基本上是类似下面

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 

这是我如何使用它在另一个布局XML

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

根据AA文件,这是所有必需的。但如前所述,没有任何东西可见。

谢谢。

+0

make sur that @ dimen/action_bar_height不是0 :) – Simo 2013-04-10 14:05:32

+0

@Simo谢谢你的提示。不,它不是0.事实上,我曾将ActionBar作为一个布局的一部分。现在我正在制作其他屏幕,我希望它是一个分离和可重用组件。 – kaskelotti 2013-04-11 04:35:51

回答

1

我认为你需要实现不同参数的构造函数:

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); 
} 

也许从XML创建自定义视图中使用另一个构造。这是你的代码和我工作的自定义操作栏的唯一区别。

希望它能帮助!

+0

感谢回复@jordifm。不幸的是,我现在没有使用Android,也没有改变尝试。如果你说它按照你的例子工作,我会相信并接受你的答案。 – kaskelotti 2013-10-30 06:00:55