工具栏不工作

ToolBar not work

我的代码不是很好,但我想做一个小应用程序。 我只是想重置工具栏,但那是行不通的,我在网上找到了很多解决方案,但我什么都不懂...

我的代码:

MainActivity.java

package r.antoine.gestionbbox;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

    private WebView webview;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        webview = (WebView) findViewById(R.id.webView);

        webview .getSettings() .setJavaScriptEnabled(true);
        webview.loadUrl("http://gestionbbox.lan/login.html");
        webview.setWebViewClient(new WebViewClient() {


            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }
        });

    }

}

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="r.antoine.gestionbbox.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

谢谢你的帮助

工具栏与任何其他小部件一样。重置工具栏是什么意思 所以如果你想删除它只需添加

    android:visibility="gone"

或在java代码中使用

    toolbar.setVisibility(View.GONE);

或者如果您不打算使用它,则将其从视图中完全删除。

为了更好地理解工具栏,请阅读文档。 https://developer.android.com/reference/android/support/v7/widget/Toolbar.html

在您的 styles.xml 中添加:

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

如果您想显示工具栏,请在 "Customize your theme here." 正下方。 主题风格:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

是的,太挑剔了,无法解决

  1. 使用 AppCompatActivity 而不是 Activity

  2. 如果您正在使用 Android Studio 使用 gradle 编译

'com.android.support:appcompat-v7:23.1.1'

  1. 制作 styles.xml 文件,值为

        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    
        </style>
    
  2. 在应用程序标签中的清单中使用

<application
        android:theme="@style/AppTheme"