[英]How to include Action Bar Activity in android Java
I have a an android java class which I am extends another activity , however I would also like to include my ActionbarActivity as well. 我有一个android java类,我扩展了另一个活动,但我也想包括我的ActionbarActivity。 The code I have below does not seem to do the trick.
我下面的代码似乎没有做到这一点。
public class ExpandableListMainActivity extends ExpandableListActivity implements ActionBarActivity
First of all, ActionBarActivity
is deprecated.You should use AppCompatActivity
instead. 首先,不推荐使用
ActionBarActivity
。您应该使用AppCompatActivity
。
Why was ActionBarActivity deprecated 为什么不赞成使用ActionBarActivity
Secondly, extends ExpandableListActivity implements ActionBarActivity
won't work. 其次,
extends ExpandableListActivity implements ActionBarActivity
将无法正常工作。
Use it like this instead : 改为使用它:
public class ExpandableListMainActivity extends AppCompatActivity
For reasons: Implements vs extends: When to use? 原因: Implements vs extends:何时使用? What's the difference?
有什么不同?
implements is for implementing an interface
implements用于实现接口
extends is for extending a class .
extends用于扩展类 。
So, that's not an interface. 所以,这不是一个界面。
Your Activity should extends AppCompactActivity
and then you should declare an ExpandableListView
in XML layout for the Activity. 您的Activity应该扩展
AppCompactActivity
,然后您应该为Activity的XML布局声明一个ExpandableListView
。
In onCreate
of the Activity : setContentView(that_xml_file);
在
onCreate
of Activity中: setContentView(that_xml_file);
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ExpandableListView>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.