最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android iconify 使用詳解

 更新時間:2017年08月01日 08:37:31   作者:智慧云端日記  
iconify是一個矢量圖標(biāo)庫,包含使用 Dave Gandy 制作的超過370中矢量字體圖標(biāo),可以使Android應(yīng)用開發(fā)者免于制作多種適用于不同屏幕大小尺寸的圖片,從而提高開發(fā)者工作效率。下文重點給大家介紹android iconify 使用,感興趣的朋友一起學(xué)習(xí)吧

android-iconify 使用詳解 ,下文圖文并茂給大家介紹的非常詳細(xì),具體內(nèi)容詳情請參考下文。

1、android-iconify簡介

  • iconify的github地址:https://github.com/JoanZapata/android-iconify
  • 項目地址:http://joanzapata.com/android-iconify
  • iconify是一個矢量圖標(biāo)庫,包含使用 Dave Gandy 制作的超過370中矢量字體圖標(biāo),可以使Android應(yīng)用開發(fā)者免于制作多種適用于不同屏幕大小尺寸的圖片,從而提高開發(fā)者工作效率。
  • 適用場景:

1、iconify原作者提供了三種他自定義的控件:IconTextView、IconButton、IconToggleButton,可以直接使用這三類控件來顯示iconify中提供的字體圖標(biāo);

2、在java代碼中通過使用一個IconDrawable為具有setIcon(Drawable drawable)方法的控件設(shè)置該字體圖標(biāo)

  • 優(yōu)點:由于這些圖標(biāo)均是矢量字體圖標(biāo),所以不僅可以無限放大而不會失真,模糊,而且可以將適用于text的屬性應(yīng)用于這些矢量圖標(biāo)上,從而實現(xiàn)改變圖標(biāo)顏色、添加陰影等效果
  • 缺點:目前在xml文件中使用圖標(biāo)庫中的資源時,需要自己對照查閱不同圖標(biāo)所對應(yīng)的標(biāo)記,自己手敲標(biāo)記,這樣不僅麻煩,而且容易出錯。

2、使用android-iconify

2.1 添加依賴

在需要使用iconify的app的build.gradle的dependencies中添加依賴(下面添加了整個庫,在實際開發(fā)過程中,可以只添加自己需要的某一個或幾個庫即可):

dependencies {
  compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2' // (v4.5)
  compile 'com.joanzapata.iconify:android-iconify-entypo:2.2.2' // (v3,2015)
  compile 'com.joanzapata.iconify:android-iconify-typicons:2.2.2' // (v2.0.7)
  compile 'com.joanzapata.iconify:android-iconify-material:2.2.2' // (v2.0.0)
  compile 'com.joanzapata.iconify:android-iconify-material-community:2.2.2' // (v1.4.57)
  compile 'com.joanzapata.iconify:android-iconify-meteocons:2.2.2' // (latest)
  compile 'com.joanzapata.iconify:android-iconify-weathericons:2.2.2' // (v2.0)
  compile 'com.joanzapata.iconify:android-iconify-simplelineicons:2.2.2' // (v1.0.0)
  compile 'com.joanzapata.iconify:android-iconify-ionicons:2.2.2' // (v2.0.1)
}

2.2 初始化android-iconify

自定義一個繼承自Application類的類:

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());
  }
}

2.3 配置Application

<application
  android:name="com.application.MyApplication"
  android:icon="@mipmap/ic_launcher"
  android:label="@string/app_name">

2.4 在布局文件中的使用

其中fa xxx 是Font Awesome的圖標(biāo)庫。icon-scan icon-wx-pay 是自定義阿里圖標(biāo)庫

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">
  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="100dp"
    android:layout_marginTop="30dp"
    android:gravity="center"
    android:orientation="vertical">
    <TextView
      android:id="@+id/id_tv"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="example delegate"
      tools:ignore="HardcodedText" />
    <com.joanzapata.iconify.widget.IconTextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:shadowColor="#22000000"
      android:shadowDx="0"
      android:shadowDy="5"
      android:shadowRadius="1"
      android:text="Welcome {fa-smile-o} {fa-hand-peace-o} !"
      android:textColor="#2A9BDA"
      android:textSize="30sp" />
    <com.joanzapata.iconify.widget.IconTextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:shadowColor="#22000000"
      android:shadowDx="3"
      android:shadowDy="3"
      android:shadowRadius="1"
      android:text="I {fa-heart-o} to {fa-code} on {fa-android}"
      android:textColor="#FF0000"
      android:textSize="40sp" />
    <com.joanzapata.iconify.widget.IconButton
      android:id="@+id/id_icon_ib"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@null"
      android:clickable="true"
      android:shadowColor="#22000000"
      android:shadowDx="3"
      android:shadowDy="3"
      android:shadowRadius="1"
      android:text="I {fa-heart-o}"
      android:textColor="@color/selector_text_press_color"
      android:textSize="40sp" />
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="20dp"
      android:gravity="center"
      android:orientation="horizontal">
      <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/alipay_button_style" />
      <ImageButton
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginLeft="30dp"
        android:background="@drawable/wx_button_style" />
    </LinearLayout>
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="20dp"
      android:gravity="center"
      android:orientation="horizontal">
      <com.joanzapata.iconify.widget.IconTextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:clickable="true"
        android:shadowColor="#22000000"
        android:text="{fa-weixin}"
        android:textColor="@color/selector_text_press_color"
        android:textSize="40sp" />
      <com.joanzapata.iconify.widget.IconTextView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginLeft="30dp"
        android:clickable="true"
        android:text="{fa-cc-visa}"
        android:textColor="@color/selector_text_press_color"
        android:textSize="40sp" />
    </LinearLayout>
    <com.joanzapata.iconify.widget.IconTextView
      android:id="@+id/id_itv_wxicon"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dp"
      android:text="{icon-scan}"
      android:textSize="40sp" />
    <com.joanzapata.iconify.widget.IconTextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginTop="10dp"
      android:text="{icon-wx-pay}"
      android:textSize="40sp" />
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_marginBottom="30dp"
      android:layout_marginTop="10dp"
      android:gravity="center"
      android:orientation="horizontal">
      <com.joanzapata.iconify.widget.IconTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="{fa-cog}"
        android:textSize="30dp" />
      <com.joanzapata.iconify.widget.IconTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:text="{fa-cog spin}"
        android:textSize="30dp" />
      <com.joanzapata.iconify.widget.IconTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:text="{fa-refresh spin}"
        android:textSize="30dp" />
      <com.joanzapata.iconify.widget.IconTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:text="{fa-spinner spin}"
        android:textSize="30dp" />
      <ImageView
        android:id="@+id/id_iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp" />
    </LinearLayout>
  </LinearLayout>
</ScrollView>

3、自定義FontModule

3.1 下載資源


3.2 添加資源自定義FontModule

將上文截圖中的 iconfont.ttf 復(fù)制到assets目錄

自定義FontModule可以參考FontAwesomeModule,需要實現(xiàn)IconFontDescriptor 接口以及實現(xiàn)Icon接口來添加我們具體的圖標(biāo)

public class IconFontModule implements IconFontDescriptor {
  @Override
  public String ttfFileName() {
    return "iconfont.ttf";//上文復(fù)制的字體文件
  }
  @Override
  public Icon[] characters() {
    return IconFonts.values();
  }
}
public enum IconFonts implements Icon {
  //&#xe609 將/&#x替換成\u
  icon_scan('\ue609'),
  icon_ali_pay('\ue65e'),
  icon_wx_pay('\ue615'),
  icon_qq_pay('\ue60d');
  private char character;
  IconFonts(char character) {
    this.character = character;
  }
  @Override
  public String key() {
    return name().replace('_', '-');
  }
  @Override
  public char character() {
    return character;
  }
}

4、在代碼中使用

IconDrawable iconDrawable = new IconDrawable(this, FontAwesomeIcons.fa_key)
        .colorRes(R.color.colorAccent)
        .actionBarSize();
imageView.setImageDrawable(iconDrawable);

5、使用到的資源文件

支付寶默認(rèn)狀態(tài) 支付寶點擊狀態(tài) 微信正常狀態(tài) 微信點擊狀態(tài)   

selector_text_press_color.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true" android:color="@color/colorAccent"/>
  <item android:color="@color/colorGreen"/>
</selector>

alipay_button_style.xml

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true" android:drawable="@drawable/alipay_pressed" />
  <item android:drawable="@drawable/alipay_normal" />
</selector>

wx_button_style.xml

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true"  android:drawable="@drawable/wx_pressed" />
  <item android:drawable="@drawable/wx_normal" />
</selector>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <color name="colorPrimary">#3F51B5</color>
  <color name="colorPrimaryDark">#303F9F</color>
  <color name="colorAccent">#FF4081</color>
  <color name="colorGreen">#04b00f</color>
</resources>

總結(jié)

以上所述是小編給大家介紹的Android iconify 使用詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android用注解與反射實現(xiàn)Butterknife功能

    Android用注解與反射實現(xiàn)Butterknife功能

    Butterknife是一個在android上實現(xiàn)ioc(控制反轉(zhuǎn))的一個庫。ioc的核心是解耦。解耦的目的是修改耦合對象時不影響另外一個對象,降低模塊之間的關(guān)聯(lián)。在Spring中ioc更多的是依靠xml的配置。而android上的IOC框架可以不使用xml配置
    2022-11-11
  • Android框架Volley使用:ImageRequest請求實現(xiàn)圖片加載

    Android框架Volley使用:ImageRequest請求實現(xiàn)圖片加載

    這篇文章主要介紹了Android框架Volley使用:ImageRequest請求實現(xiàn)圖片加載的相關(guān)知識,非常不錯,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2019-05-05
  • Android最新狀態(tài)欄處理介紹

    Android最新狀態(tài)欄處理介紹

    大家好,本篇文章主要講的是Android最新狀態(tài)欄處理介紹,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • Android畫廊效果之ViewPager顯示多個圖片

    Android畫廊效果之ViewPager顯示多個圖片

    這篇文章主要為大家詳細(xì)介紹了Android畫廊效果之ViewPager顯示多個圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • android自定義Toast設(shè)定顯示時間

    android自定義Toast設(shè)定顯示時間

    這篇文章主要為大家詳細(xì)介紹了android自定義Toast設(shè)定顯示時間,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • flutter  TextField換行自適應(yīng)的實現(xiàn)

    flutter TextField換行自適應(yīng)的實現(xiàn)

    這篇文章主要介紹了flutter TextField換行自適應(yīng)的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • Android?ViewModel創(chuàng)建不受橫豎屏切換影響原理詳解

    Android?ViewModel創(chuàng)建不受橫豎屏切換影響原理詳解

    這篇文章主要為大家介紹了Android?ViewModel創(chuàng)建不受橫豎屏切換影響原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • Android圖片加載的緩存類

    Android圖片加載的緩存類

    這篇文章主要為大家詳細(xì)介紹了Android圖片加載的緩存類的相關(guān)資料,需要的朋友可以參考下
    2016-02-02
  • Android Handler消息傳遞機制

    Android Handler消息傳遞機制

    Handler是一套 Android 消息傳遞機制,主要用于線程間通信。用最簡單的話描述: handler其實就是主線程在起了一個子線程,子線程運行并生成Message,Looper獲取message并傳遞給Handler,Handler逐個獲取子線程中的Message
    2022-12-12
  • Android 限制edittext 整數(shù)和小數(shù)位數(shù) 過濾器(詳解)

    Android 限制edittext 整數(shù)和小數(shù)位數(shù) 過濾器(詳解)

    下面小編就為大家?guī)硪黄狝ndroid 限制edittext 整數(shù)和小數(shù)位數(shù) 過濾器(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-04-04

最新評論

尼木县| 阜平县| 富锦市| 长葛市| 松江区| 黄平县| 讷河市| 白河县| 清水河县| 辽中县| 渝北区| 新密市| 墨玉县| 滁州市| 上饶县| 武鸣县| 明溪县| 双峰县| 长顺县| 固安县| 乐昌市| 吴忠市| 文水县| 平泉县| 城步| 浦城县| 通江县| 巴中市| 安国市| 封开县| 阿巴嘎旗| 积石山| 武平县| 太白县| 安达市| 青神县| 澜沧| 玉山县| 茌平县| 随州市| 德钦县|