android ActionBar没有扩展ActionBarActivity?

时间:2015-04-27 12:43:40

标签: android

我想在不延长var json = { test: { "name":"test", "age":"99" } ^^ ^^ no semi-colon }; 的情况下使用ActionBar,因为我已经扩展了ActionBarActivity。  有人可以帮忙吗?

我做过类似的事情。在此我想实施Action Bar

TabActivity

2 个答案:

答案 0 :(得分:0)

试试我的代码。您将能够使用操作栏和tabhost创建片段。

1) XML file for Activity:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <HorizontalScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            android:scrollbars="none">

        <TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>
        </HorizontalScrollView>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    </LinearLayout>
</android.support.v4.app.FragmentTabHost>


2) Java code for Activity:

    public class CarsActivity extends FragmentActivity implements   YourFragment.OnFragmentInteractionListener
    {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
     _mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
     _mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
     //add your fragments here:
     _mTabHost.addTab(_mTabHost.newTabSpec("*UNIQE IDENTIFIER OF YOUR    FRAGMENT").setIndicator("*DISPLAY NAME ON TAB*"),
                YourFragment.class, null);
    }
    });
     @Override
     public void onFragmentInteraction(Uri uri)
      {}

    }

答案 1 :(得分:0)

您可以在getActionBar()中使用oncreate(),或者如果您想创建自定义操作栏,请使用以下代码。

    // Action Bar Customization
    ActionBar ab =act.getActionBar();

    ColorDrawable colorDrawable = new ColorDrawable(act.getResources().getColor(color.ActionBar_bg));
    ab.setBackgroundDrawable(colorDrawable);

    //ab.setBackgroundDrawable(act.getResources().getDrawable(R.drawable.header));
    ab.setDisplayShowTitleEnabled(false); // disables default title on
                                            // actionbar.
    ab.setDisplayShowCustomEnabled(true); // enables custom view.
    ab.setDisplayShowHomeEnabled(false); // hides app icon.
    ab.setTitle("");
    // Inflating Layout
    LayoutInflater inflater = (LayoutInflater) act.getActionBar()
            .getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);

    View customActionBar = inflater.inflate(R.layout.actionbar_layout, null);

    imgapplogo = (ImageView) customActionBar.findViewById(R.id.app_logo);
    img_back=(ImageView)customActionBar.findViewById(R.id.imgBack);