简体   繁体   English

动作栏未显示在ListActivity中

[英]Actionbar not showing in ListActivity

I have met with a problem that i cannot see my actionbar when the MainActivity extends ListActivity. 我遇到了一个问题,当MainActivity扩展ListActivity时,我看不到我的操作栏。 I have read some questions and answers showing it is the problem with the theme. 我已经阅读了一些问题和答案,表明这是主题的问题。 So i changed <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> to <style name="AppTheme" parent="android:Theme.Holo"> then i got the old weird looking Actionbar. 因此,我将<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">更改为<style name="AppTheme" parent="android:Theme.Holo">然后,我得到了看起来很古怪的Actionbar。

I want the new styled Actionbar in ListActivity. 我想要ListActivity中新样式的Actionbar。

Manifest 表现

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <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>

MainActivity.java MainActivity.java

package com.example.myapp;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class MainActivity extends ListActivity  {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);
        return super.onCreateOptionsMenu(menu);
    }
}

activity_main.xml activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"  >

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@android:id/list"
        android:layout_weight="1"
        android:layout_margin="5dp"/>


</LinearLayout>

These are my codes.I want to use my new Actionbar when extending ListActivity. 这些是我的代码。扩展ListActivity时,我想使用新的Actionbar。

Any help appretiated 任何帮助

You should use Toolbar, ActionBar is deprecated. 您应该使用工具栏,不推荐使用ActionBar。

Check this: 检查一下:

http://www.android4devs.com/2014/12/how-to-make-material-design-app.html http://www.android4devs.com/2014/12/how-to-make-material-design-app.html

Check this project to learn how to use Android Support Design Library: 检查此项目以了解如何使用Android支持设计库:

https://github.com/chrisbanes/cheesesquare https://github.com/chrisbanes/cheesesquare

Best regards! 最好的祝福!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM