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

问题描述

我想构建自己的应用程序并向其添加操作栏.在我的主布局中,我只需要一个仅带有应用程序名称的操作栏.在其他布局/页面中,我需要我的页面名称和背面导航符号,该符号可导航回上一页.有人可以告诉我如何执行此操作,也可以有人告诉我有关android中默认的操作栏的作用和用途.

I want to build my own app and i want to add an action bar to it.In my main layout i want an action bar with my app name only.In my other layouts/pages i want my page name and a back navigating symbol which navigates back to the previous page.Can anybody tell me how to do this and also can somebody tell me about the default actionbar in android what it does and what do i do with it.

推荐答案

步骤1:build.gradle(应用程序级别)

STEP 1 : build.gradle (Application Level)

dependencies {
    compile 'com.android.support:appcompat-v7:23.3.0'
}

第2步:AndroidManifest.xml

STEP 2 : AndroidManifest.xml

<application
....
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"/>

第3步:在您的活动中

public class main extends AppCompatActivity
{
    ....
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        ...

        getSupportActionBar().setTitle("Your Activity Title"); // for set actionbar title
        getSupportActionBar().setDisplayHomeAsUpEnabled(true); // for add back arrow in action bar
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();
    }
    return super.onOptionsItemSelected(item);
}

这篇关于如何在Android Studio中为初学者添加动作栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:02