Android Studio工具栏自动显示

斯特菲耶夫

我是来自iOS开发的全新Android开发人员。我现在要做的就是使用api 21启动带有基本工具栏的应用程序。但是,当我这样做时,它会在看似相同的栏下面添加工具栏。删除工具栏后,其他栏仍然存在。所有Android应用程序的默认设置是否都具有一个工具栏,其应用程序名称内置在顶部?如何添加动作/自定义此默认工具栏?

这是我的xml:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sample_main_layout"></LinearLayout>

这是我的主要活动:

公共类MainActivity扩展了AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //toolbar.setTitle("Groups");
}

}

这是我列出的代码的结果

从字面上看,这是我项目的范围,尽管我已经在线搜索了一段时间,但每个人都说我应该使用工具栏。如果这不是工具栏,那又是什么?我为我的幼稚而道歉。

邹国荣

您应该在样式中设置此项以隐藏默认的ActionBar。

<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>

在您的布局中,您可以添加工具栏

<android.support.v7.widget.Toolbar
    android:id="@+id/main_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

并在活动中

Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章