簡體   English   中英

如何在Android Java中包含Action Bar Activity

[英]How to include Action Bar Activity in android Java

我有一個android java類,我擴展了另一個活動,但我也想包括我的ActionbarActivity。 我下面的代碼似乎沒有做到這一點。

public class ExpandableListMainActivity extends ExpandableListActivity   implements ActionBarActivity  

首先,不推薦使用ActionBarActivity 。您應該使用AppCompatActivity

為什么不贊成使用ActionBarActivity

其次, 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM