如何支持早期的android版本?

时间:2019-01-15 21:10:29

标签: android android-appcompat

我开发了一个可扩展appcompat并使用cardview和grideview的android应用,它在我的智能手机上运行正常,但在运行kitkat的平板电脑上却崩溃了。

这是main.xml: 我在单独的filde中使用了toobar,因此可以在其他活动中使用它。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:gravity="center_horizontal">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"/>

    </android.support.design.widget.AppBarLayout>

    <GridView
        android:gravity="center"
        android:id="@+id/gv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:columnWidth="150dp"
        android:numColumns="2"
        android:stretchMode="columnWidth"
        android:horizontalSpacing="12dp"
        android:verticalSpacing="12dp"
        android:layout_centerVertical="true"
        android:paddingRight="10dp"/>

</RelativeLayout>

Card_view.xml: 我将cardview用于gridview

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="#3F51B5"
    app:cardCornerRadius="8dp"
    app:cardElevation="4dp"
    android:id="@+id/card"
    style="@style/AppTheme"
    android:gravity="center"
    android:foreground="?attr/selectableItemBackground"
    android:stateListAnimator="@anim/card_animation"
    android:clickable="false">

    <LinearLayout
        android:layout_height="150dp"
        android:layout_width="wrap_content"
        style="@style/AppTheme"
        android:gravity="center"
        android:orientation="vertical">

        <TextView
            android:background="#CD2DD9"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="#fff"
            android:id="@+id/title"
            style="@style/AppTheme"
            android:textSize="20sp"
            android:gravity="center"/>

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/title"
            android:id="@+id/img"
            style="@style/AppTheme"/>

    </LinearLayout>

</android.support.v7.widget.CardView>

AndroidManifest.xml:

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

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

        <activity
            android:name=".BaseVideo"
            android:label="@string/app_name" >

        </activity>

        <activity
            android:name=".HandWork"
            android:label="@string/app_name" >

        </activity>

        <activity
            android:name=".Smart"
            android:label="@string/app_name" >

        </activity>
        <activity
            android:name=".Science"
            android:label="@string/app_name" >

        </activity>
        <activity
            android:name=".Fact"
            android:label="@string/app_name" >

        </activity>
    </application>

</manifest>

build.gradle:

apply plugin:'com.android.application'
android {
    compileSdkVersion 26
    buildToolsVersion "26.1.0"

    defaultConfig {
        applicationId "aridge.chahid_wa.taalam"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.5.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

我的代码有什么问题?

0 个答案:

没有答案
相关问题