Android ActionBarCompat, action bar doesn't display correctly

给你一囗甜甜゛ 提交于 2019-12-06 15:56:33

问题


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

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.

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

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>

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 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>

What am I doing wrong?


回答1:


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+"


来源:https://stackoverflow.com/questions/22743527/android-actionbarcompat-action-bar-doesnt-display-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!