AppCompactActivity中的setSupportActionBar无法应用于android

时间:2018-08-10 16:12:40

标签: android android-layout android-toolbar

我无法在我的应用程序中添加动作栏,并且不断显示错误,此外,当我添加工具栏时,它在布局中未显示任何内容

下面是代码的屏幕截图::

enter image description here

完整代码如下... >>>>

package com.example.prateek.holachat;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;    
import android.view.Menu;    
import android.widget.Toolbar;    
import com.google.firebase.auth.FirebaseAuth;   
import com.google.firebase.auth.FirebaseUser;

public class MainActivity extends AppCompatActivity {

    private FirebaseAuth mAuth;
    private Toolbar mtoolBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mAuth = FirebaseAuth.getInstance();

        mtoolBar = (Toolbar) findViewById(R.id.toolBarNew);
        setSupportActionBar(mtoolBar);
        getSupportActionBar().setTitle("HOLA !");


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);

        getMenuInflater().inflate(R.menu.main_menu,menu);

        return true;
    }


    @Override
    public void onStart() {
        super.onStart();
        // Check if user is signed in (non-null) and update UI accordingly.
        FirebaseUser currentUser = mAuth.getCurrentUser();

        if (currentUser == null) {

            Intent startIntent = new Intent(MainActivity.this,StartActivity.class);
            startActivity(startIntent);
            finish();

        }


    }


     }

这是toolBar XML文件的屏幕截图。.>>>>

enter image description here

1 个答案:

答案 0 :(得分:0)

所有v7库都用于支持具有旧android版本的设备。如果您想提供支持,请将Observable.fromIterable(data) .filter(it->it!=null && it.toLowerCase().contains(newText.toLowerCase())) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .toList() .subscribe(strings -> { int key = 0; for (String suggestion : strings) { suggestionsCursor.addRow(new Object[]{key++, suggestion}); } }, error -> { /* handle exceptions here */ }); import android.support.v7.widget.Toolbar

否则,根据您的情况,您有setSupportActionBar(),请改用import android.widget.Toolbar;