麻烦的图标

时间:2017-01-25 15:33:17

标签: java android android-studio

我已经使用Mike Penz的MaterialDrawer实现了一个NavigationDrawer。 它工作正常,但当我尝试更换图标" FontAwesome"在" GoogleMaterial"或其他人得到错误"不幸的是,App已停止。" 所有只使用图标" FontAwesome" 怎样才能解决这个问题? 提前谢谢!

MainActivity.java:

<script>alert('test');</script>

activity_main.xml中:

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;

import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.mikepenz.iconics.typeface.FontAwesome;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;

public class MainActivity extends ActionBarActivity {

    private Drawer.Result drawerResult = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Handle Toolbar
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.getBackground().setAlpha(100);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        drawerResult = new Drawer()
                .withActivity(this)
                .withToolbar(toolbar)
                .withActionBarDrawerToggle(true)
                .withHeader(R.layout.drawer_header)
                .addDrawerItems(
                        new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home),
                        new PrimaryDrawerItem().withName(R.string.drawer_item_database).withIcon(FontAwesome.Icon.faw_database),
                        new PrimaryDrawerItem().withName(R.string.drawer_item_map).withIcon(FontAwesome.Icon.faw_map_marker),
                        new PrimaryDrawerItem().withName(R.string.drawer_item_guides).withIcon(FontAwesome.Icon.faw_book),
                        new PrimaryDrawerItem().withName(R.string.drawer_item_crafting).withIcon(GoogleMaterial.Icon.gmd_build),
                        //new PrimaryDrawerItem().withName(R.string.drawer_item_tools).withIcon(GoogleMaterial.Icon.gmd_build),
                        new PrimaryDrawerItem().withName(R.string.drawer_item_links).withIcon(FontAwesome.Icon.faw_link),
                        new DividerDrawerItem(),
                        //new PrimaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(GoogleMaterial.Icon.gmd_settings),
                        new PrimaryDrawerItem().withName(R.string.drawer_item_feedback).withIcon(FontAwesome.Icon.faw_envelope)
                        //new PrimaryDrawerItem().withName(R.string.drawer_item_changes).withIcon(Typeicons.Icon.typ_clipboard)
                )
                .build();
    }

    @Override
    public void onBackPressed() {
        if (drawerResult.isDrawerOpen()) {
            drawerResult.closeDrawer();
        } else {
            super.onBackPressed();
        }
    }
}

的build.gradle:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/blackToolbar"
            android:elevation="4dp"
            android:minHeight="?attr/actionBarSize"
            android:paddingTop="@dimen/tool_bar_top_padding"
            android:transitionName="actionBar" />

</RelativeLayout>

的AndroidManifest.xml

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "org.enotboris.app"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile('com.mikepenz.materialdrawer:library:0.9.5@aar') {
        transitive = true
    }
    compile 'com.mikepenz:google-material-typeface:2.2.0.3.original@aar'
    compile 'com.mikepenz:devicon-typeface:2.0.0.2@aar'
    compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.2@aar'
    compile 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar'
    compile 'com.mikepenz:octicons-typeface:3.2.0.2@aar'
    compile 'com.mikepenz:meteocons-typeface:1.1.0.2@aar'
    compile 'com.mikepenz:community-material-typeface:1.7.22.1@aar'
    compile 'com.mikepenz:weather-icons-typeface:2.0.10.2@aar'
    compile 'com.mikepenz:typeicons-typeface:2.0.7.2@aar'
    compile 'com.mikepenz:entypo-typeface:1.0.0.2@aar'
    compile 'com.mikepenz:devicon-typeface:2.0.0.2@aar'
    compile 'com.mikepenz:foundation-icons-typeface:3.0.0.2@aar'
    compile 'com.mikepenz:ionicons-typeface:2.0.1.2@aar'
    testCompile 'junit:junit:4.12'
}

logcat的:

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

样品:

With "FontAwesome" icons

With "GoogleMaterialDesign" and other icons

1 个答案:

答案 0 :(得分:1)

解决方案:

Iconics.init(getApplicationContext());
Iconics.registerFont(new GoogleMaterial());

感谢您的时间!