Android ActionBarCompat,操作栏无法正确显示 [英] Android ActionBarCompat, action bar doesn't display correctly

查看:63
本文介绍了Android ActionBarCompat,操作栏无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将android.support.v7库用于旧设备上的操作栏支持,并将android.support.v4用于片段支持.

I am using android.support.v7 library for action bar support on old devices and android.support.v4 for fragment support.

我在Android 2. *版本上的应用程序无法正确显示ActionBar,它被拉伸以填满屏幕,并且框架布局未显示.可单击ActionBarDrawerToggle按钮,但不会执行任何操作.

My application on version Android 2.* doesn't display ActionBar correctly, it stretched to fill the screen and frame layout doesn't showing. ActionBarDrawerToggle button clickable, but it doesn't do anything.

LogCat输出中未显示任何错误或警告.

There are no errors or warnings shown in the LogCat output.

AndroidManifest.xml:

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar" >
        <activity
            android:name="com.example.test.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中:

In MainActivity:

...
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.OnNavigationListener;
import android.support.v7.app.ActionBarActivity;

...
public class MainActivity extends ActionBarActivity
...

MainActivity布局:

MainActivity layout:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <!-- The main list content view -->
    <FrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The navigation drawer -->
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:background="@color/light_gray"
        android:dividerHeight="0dp" />
</android.support.v4.widget.DrawerLayout>

我在做什么错了?

推荐答案

我解决了此问题,方法是从"libs"文件夹中删除v4 jar支持库,并删除从eclipse项目导入的v7支持库文件夹,并将其添加到依赖项部分中的build.gradle文件:

I solved this problem by removing v4 jar support library from "libs" folder and removing v7 support library folder, which has been imported from eclipse project and adding this to build.gradle file in dependencies section:

compile "com.android.support:support-v4:18.0.+"
compile "com.android.support:appcompat-v7:19.1.0+"

这篇关于Android ActionBarCompat,操作栏无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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