这是工具栏布局的 XML...
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.Toolbar>
我正在使用支持库将工具栏用作我的操作栏。我在 onCreate 中这样做了...
Toolbar mToolbar = (Toolbar)getLayoutInflater().inflate(R.layout.toolbar, null);
setActionBar(mToolbar);
但是如果给我红色波浪线并告诉我标题中的信息。我想,LULWUT?!
最佳答案
您可能需要 setSupportActionBar
反而。使用 Toolbar
意味着您应该使用 AppCompatActivity
,所有这些东西都在 appcompat (~support) 库中。
编辑:如果您使用现已弃用的 ActionBarActivity
,此答案仍然适用,因为 ActionBarActivity
inherits the setSupportActionBar
method from AppCompactActivity
.
关于android - Activity 类型中的方法 setActionBar(Toolbar) 不适用于参数 (Toolbar),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29637565/