获取“在类型AppCompatActivity的方法setSupportActionBar(工具栏)是不适用的参数(工具栏)”在我的AppCompatActivity [英] Getting 'The method setSupportActionBar(Toolbar) in the type AppCompatActivity is not applicable for the arguments (Toolbar)' in my AppCompatActivity

查看:293
本文介绍了获取“在类型AppCompatActivity的方法setSupportActionBar(工具栏)是不适用的参数(工具栏)”在我的AppCompatActivity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我升级游戏,我以前建立了一些时间的UI和我对谷歌的材料设计走向。由于code升级的一部分,我安装了向后兼容支持库,Android的支持-V7-应用程序兼容性,到我的Eclipse项目和扩展的主要活动AppCompatActivity,像这样:

I'm upgrading the UI of a game that I built some time ago and am heading toward Google's Material Design. As part of the code upgrade, I installed the backwards compatibility support library, android-support-v7-appcompat, into my Eclipse project and extended the main activity to AppCompatActivity, like so:

public class FivetoGo extends AppCompatActivity {
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

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

但是当我打电话setSupportActionBar(),我得到上述错误。下面是main.xml中:

but when I call setSupportActionBar(), I get the above error. Here's main.xml:

<?xml version='1.0' encoding='UTF-8' ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <android.support.v7.widget.Toolbar 
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ff6d7fe2"
        android:minHeight="?android:attr/actionBarSize"
        app:contentInsetEnd="0dp"
        app:contentInsetStart="0dp" >
    </android.support.v7.widget.Toolbar>

    <Button android:id="@+id/intro_button"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:text="@string/rules"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView android:id="@+id/secret_word_label"
        android:layout_below="@id/intro_button"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
        android:textStyle="bold"
        android:textSize="20sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/my_secret_word"/>

    <EditText android:id="@+id/my_secret_word_text"
        android:layout_below="@id/intro_button"
        android:layout_toRightOf="@id/secret_word_label"
        android:layout_alignBaseline="@id/secret_word_label"
        android:inputType="textNoSuggestions"
        android:capitalize="none"
        android:maxLength="5"
        android:textSize="20sp"
        android:layout_width="100dp"
        android:layout_height="wrap_content"/>

    <Button android:id="@+id/done_button_main"
        android:layout_below="@id/intro_button"
        android:layout_toRightOf="@id/my_secret_word_text"
        android:layout_alignBaseline="@id/my_secret_word_text"
        android:enabled="false"
        android:layout_margin="10dp"
        android:text="@string/done_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView android:id="@+id/language_label"
        android:layout_below="@id/my_secret_word_text"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="20dp"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/language"/>

    <Spinner android:id="@+id/language_list"
        android:layout_below="@id/my_secret_word_text"
        android:layout_toRightOf="@id/language_label"
        android:layout_alignBaseline="@id/language_label"
        android:layout_marginTop="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:prompt="@string/language"/>

    <Button android:id="@+id/word_list_button"
        android:layout_below="@id/my_secret_word_text"
        android:layout_toRightOf="@id/language_list"
        android:layout_alignBaseline="@id/language_list"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="20dip"
        android:text="@string/word_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView android:id="@+id/level_label"
        android:layout_below="@id/word_list_button"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="20dp"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/level"/>

    <Spinner android:id="@+id/level_spinner"
        android:layout_below="@id/language_list"
        android:layout_toRightOf="@id/level_label"
        android:layout_alignBaseline="@id/level_label"
        android:layout_marginTop="30dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button android:id="@+id/quit_button"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/level_spinner"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="20dp"
        android:text="@string/quit_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</RelativeLayout>

看不到我在做什么错。感谢您的帮助。

Can't see what I'm doing wrong. Thanks for any help.

推荐答案

修改

import android.widget.Toolbar;

import android.support.v7.widget.Toolbar;

在Java源代码code是presumably出现上述你已经在你的问题所示的情况。 : - )

in the Java source code that presumably appears above what you have shown in your question. :-)

这篇关于获取“在类型AppCompatActivity的方法setSupportActionBar(工具栏)是不适用的参数(工具栏)”在我的AppCompatActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆