[英]How to include Action Bar Activity in android Java
我有一個android java類,我擴展了另一個活動,但我也想包括我的ActionbarActivity。 我下面的代碼似乎沒有做到這一點。
public class ExpandableListMainActivity extends ExpandableListActivity implements ActionBarActivity
首先,不推薦使用ActionBarActivity
。您應該使用AppCompatActivity
。
其次, extends ExpandableListActivity implements ActionBarActivity
將無法正常工作。
改為使用它:
public class ExpandableListMainActivity extends AppCompatActivity
原因: Implements vs extends:何時使用? 有什么不同?
implements用於實現接口
extends用於擴展類 。
所以,這不是一個界面。
您的Activity應該擴展AppCompactActivity
,然后您應該為Activity的XML布局聲明一個ExpandableListView
。
在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.