gpt4 book ai didi

java - ANDROID:无法解析方法 getSupportActionBar()

转载 作者:搜寻专家 更新时间:2023-10-30 20:56:03 25 4
gpt4 key购买 nike

这件事让我抓狂。我似乎无法让我的应用程序正确编译。我通过复制 jar 文件,将它们放入 libs 文件夹,右键单击并将它们添加为库,在我的应用程序中添加了支持库。

我已尝试扩展 ActionBaractivity,但仍然无法识别该方法。

我使用的是 Android Studio 版本 0.8.2。

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class mainActivity extends Activity implements AdapterView.OnItemClickListener {

private DrawerLayout drawerLayout;
private ListView listView;
private String[] navMenuArray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
navMenuArray = getResources().getStringArray(R.array.navmenu);
listView =(ListView) findViewById(R.id.drawerList);
listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_expandable_list_item_1, navMenuArray));
listView.setOnItemClickListener(this);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//handles what happens when an item in the menu is clicked
Toast.makeText(this,navMenuArray[position]+" was selected", Toast.LENGTH_SHORT).show();
selectItem(position);
}
public void selectItem(int position){
listView.setItemChecked(position, true);
setTitle(navMenuArray[position]);
}
public void setTitle(String title){
getSupportActionbar().setTitle(title);
}
}

list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp" >

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat" >
<activity
android:name=".mainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 20
buildToolsVersion '20.0.0'

defaultConfig {
applicationId "com.myapp"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
}

最佳答案

你需要把Activity改成ActionBarActivity

公共(public)类 mainActivity 扩展了 ActionBarActivity

ActionBarActivity 已被弃用,因此请使用以下内容

公共(public)类 mainActivity 扩展 AppCompatActivity

关于java - ANDROID:无法解析方法 getSupportActionBar(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25100179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com