简体   繁体   中英

Android Studio Toolbar Automatically showing up

I am a brand new Android developer coming over from iOS development. All I want to do right now is launch an app with a basic Toolbar using api 21. However, when I do do, it adds the toolbar underneath a seemingly identical bar. Upon removing the toolbar, the other bar is still present. Is this default for all Android apps to have a toolbar with the app name built into the top? How do I add actions/customize this default toolbar?

Here is my 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>

And here is my main activity:

public class MainActivity extends 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");
}

}

这是我列出的代码的结果

This is literally the extent of my project, and though I have been searching online for a while everyone says I should be using a Toolbar. If this is not a Toolbar then what is it then? I apologize for my naivety.

You should set this in your styles to hide default ActionBar.

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

In your layout, you can add ToolBar

<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" />

And in activity

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM