如何添加动作栏 [英] How to add action bar

查看:87
本文介绍了如何添加动作栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在活动上方添加操作栏.如何在以下布局中添加操作栏. 而且我想为低于11的API级别创建操作栏.任何人都可以向我提供相关的教程参考.

I want to add action bar on top of my activity. How to add action bar in the following layout. And I want to create action bar for API level less than 11. Can anyone provide me tutorial reference of that.

布局-

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/buddha"
    android:gravity="center"
    android:orientation="vertical"
    >
    <View
        android:id="@+id/top1"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:background="@null"
        android:gravity="center"
        android:layout_weight="5"
    />

    <Button
        android:id="@+id/hist"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:background="#73000000"
        android:gravity="center"
        android:textSize="@dimen/btxt"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:layout_weight="1"
        android:text="@string/his"
    />

    <View
        android:id="@+id/top2"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:background="@null"
        android:gravity="center"
        android:layout_weight=".10"
    />

    <Button
        android:id="@+id/typ"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:background="#73000000"
        android:textSize="@dimen/btxt"
        android:textStyle="bold"
        android:textColor="#FFFFFF"
        android:layout_weight="1"
        android:text="@string/typ"
    />

    <View
        android:id="@+id/top3"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:background="@null"
        android:gravity="center"
        android:layout_weight=".10"
    />

    <Button
        android:id="@+id/ben"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:layout_weight="1"
        android:textSize="@dimen/btxt"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:background="#73000000"
        android:text="@string/ben"
    />

    <View
        android:id="@+id/top4"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:background="@null"
        android:gravity="center"
        android:layout_weight=".10"
    />

    <Button
        android:id="@+id/exit"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:textSize="@dimen/btxt"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:background="#73000000"
        android:layout_weight="1"
        android:text="@string/exit"
    />

    <View
        android:id="@+id/top41"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:background="@null"
        android:gravity="center"
        android:layout_weight=".10"
    />

</LinearLayout>

推荐答案

将您的项目设置为 appcompat v7 库以供参考,请参见

setup your project to appcompat v7 library for reference see http://developer.android.com/guide/topics/ui/actionbar.html#Adding
and

@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
        | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
  }

这篇关于如何添加动作栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆