Android開發中iconify的使用

1、iconify簡介java

2、使用步驟(我使用的編譯器是Android Studio)

    1. 在須要使用iconify的app的build.gradle的dependencies中添加依賴(下面添加了整個庫,在實際開發過程當中,能夠只添加本身須要的某一個或幾個庫便可):

    2. dependencies {
          compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.1' // (v4.5)
          compile 'com.joanzapata.iconify:android-iconify-entypo:2.2.1' // (v3,2015)
          compile 'com.joanzapata.iconify:android-iconify-typicons:2.2.1' // (v2.0.7)
          compile 'com.joanzapata.iconify:android-iconify-material:2.2.1' // (v2.0.0)
          compile 'com.joanzapata.iconify:android-iconify-material-community:2.2.1' // (v1.4.57)
          compile 'com.joanzapata.iconify:android-iconify-meteocons:2.2.1' // (latest)
          compile 'com.joanzapata.iconify:android-iconify-weathericons:2.2.1' // (v2.0)
          compile 'com.joanzapata.iconify:android-iconify-simplelineicons:2.2.1' // (v1.0.0)
          compile 'com.joanzapata.iconify:android-iconify-ionicons:2.2.1' // (v2.0.1)}
    3.  自定義一個繼承自Application類的類:

    4. import android.app.Application;
      import com.joanzapata.iconify.Iconify;
      import com.joanzapata.iconify.fonts.EntypoModule;
      import com.joanzapata.iconify.fonts.FontAwesomeModule;
      import com.joanzapata.iconify.fonts.IoniconsModule;
      import com.joanzapata.iconify.fonts.MaterialCommunityModule;
      import com.joanzapata.iconify.fonts.MaterialModule;
      import com.joanzapata.iconify.fonts.MeteoconsModule;
      import com.joanzapata.iconify.fonts.SimpleLineIconsModule;
      import com.joanzapata.iconify.fonts.TypiconsModule;
      import com.joanzapata.iconify.fonts.WeathericonsModule;
      public class MyApplication extends Application {
          @Override
          public void onCreate() {
              super.onCreate();
              Iconify
                      .with(new FontAwesomeModule())
                      .with(new EntypoModule())
                      .with(new TypiconsModule())
                      .with(new MaterialModule())
                      .with(new MaterialCommunityModule())
                      .with(new MeteoconsModule())
                      .with(new WeathericonsModule())
                      .with(new SimpleLineIconsModule())
                      .with(new IoniconsModule());
          }
      }
    5.  在manifest文件中的application中聲明使用自定義的MyApplication:

    6. <application
          android:name="com.application.MyApplication"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name">
    7.  通過以上幾步就能夠在應用中使用iconify圖標了,如在佈局文件中的使用:

    8. <?xml version="1.0" encoding="utf-8"?>
      <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"
          android:paddingBottom="@dimen/activity_vertical_margin"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin"
          tools:context="com.activity.NewTaskActivity"
          android:gravity="center_horizontal">
          <com.joanzapata.iconify.widget.IconTextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/iconify_tv"
              android:text="{fa-heart @color/color_iconify_heart_pink 48sp}   {fa-star #FFFF00 44sp}   {fa-gift #FF00FF 48sp}"
              android:layout_marginTop="@dimen/activity_vertical_margin"
              android:layout_margin="@dimen/activity_horizontal_margin"
              android:gravity="center" />
          <com.joanzapata.iconify.widget.IconButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/iconify_btn"
              android:layout_below="@+id/iconify_tv"
              android:layout_marginLeft="30dp"
              android:text="{entypo-facebook #008B00 35sp}"/>
          <com.joanzapata.iconify.widget.IconToggleButton
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/iconify_toggle"
              android:layout_below="@+id/iconify_btn"
              android:layout_marginLeft="30dp"
              android:textOff="{fa-lock}"
              android:textOn="{fa-unlock}"
              android:textSize="35sp"
              android:textColor="#677EFF"/>
      </RelativeLayout>
    9.  效果圖以下:

    10.  在代碼中使用:

    11. @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.menu_main, menu);
         /* 設置menu的圖標爲iconify中的圖標*/
          menu.findItem(R.id.action_settings).setIcon(
                  new IconDrawable(this, FontAwesomeIcons.fa_user)
                          .colorRes(R.color.color_iconify_music_quartz)
                          .actionBarSize());
          return true;
      }
    12. 效果圖以下:

    13. 問題:在使用ImageView.setImageIcon(Drawable drawable)時,圖標老是沒有顯示出來,不知道什麼緣由,還須要後面再看看

相關文章
相關標籤/搜索