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

Android 改變圖標(biāo)原有顏色和搜索框的實(shí)例代碼

 更新時(shí)間:2017年09月19日 09:34:15   作者:切切歆語  
讓Android也能有iOS那么方便的圖片色調(diào)轉(zhuǎn)換,就像同一個(gè)圖標(biāo),但是有多個(gè)地方使用,并且顏色不一樣,就可以用這個(gè)方法了。 本文實(shí)現(xiàn)TextView圖片和文字居中,鍵盤搜索功能,具體實(shí)現(xiàn)代碼大家跟隨腳本之家小編看看吧

圖標(biāo)改變顏色:Drawable的變色,讓Android也能有iOS那么方便的圖片色調(diào)轉(zhuǎn)換,就像同一個(gè)圖標(biāo),但是有多個(gè)地方使用,并且顏色不一樣,就可以用這個(gè)方法了。

搜索框: 一般是EditText實(shí)現(xiàn),本文 實(shí)現(xiàn) TextView圖片和文字居中,鍵盤搜索。

來看看效果圖:

 圖標(biāo)改變顏色:第一個(gè)界面的左邊(二維碼)和右邊(更多)兩個(gè)實(shí)現(xiàn),我放進(jìn)去的圖片是黑色的,顯示出來是白色的。         

搜索框:第一個(gè)界面的圖片和文字居中,還可以設(shè)置間距,第二個(gè)見面搜索設(shè)置鍵盤搜索按鈕,點(diǎn)擊搜索監(jiān)聽事件,清除內(nèi)容的圖標(biāo)。

搜索框布局:

<!-- 
   搜索圖標(biāo)設(shè)置 左邊 
   android:drawableLeft="@mipmap/icon_search" 
   android:drawablePadding="5dp" 圖標(biāo)和文字的間距 
   右邊 
   android:drawableRight="@mipmap/round_close" 
   android:paddingRight="8dp" 
   android:imeOptions="actionSearch" 設(shè)置成搜索按鈕 
  --> 
  <EditText 
   android:id="@+id/search_text" 
   android:layout_width="0dp" 
   android:layout_weight="1" 
   android:layout_height="30dp" 
   android:hint="輸入要搜索的商品" 
   android:background="@drawable/search_gray" 
   android:layout_marginTop="10dp" 
   android:layout_marginLeft="9dp" 
   android:textSize="12sp" 
   android:drawableLeft="@mipmap/icon_search" 
   android:paddingLeft="9dp" 
   android:drawablePadding="5dp" 
   android:drawableRight="@mipmap/round_close" 
   android:paddingRight="8dp" 
   android:imeOptions="actionSearch" 
   android:maxLines="1" 
   android:singleLine="true" 
   /> 

鍵盤監(jiān)聽:

searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
   @Override 
   public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
    if ((actionId == 0 || actionId == 3) && event != null) { 
             //提示搜索內(nèi)容 
     Toast.makeText(SearchActivity.this,searchText.getText().toString(),Toast.LENGTH_LONG).show(); 
     //可以跳轉(zhuǎn)搜索頁面 
     /* Intent intent= new Intent(SearchActivity.this,SearchWebViewActivity.class); 
     intent.putExtra("model",model); 
     intent.putExtra("search",searchText.getText().toString()); 
     startActivity(intent); 
     finish();*/ 
    } 
    return false; 
   } 
  }); 

首頁布局:

<LinearLayout 
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" 
  android:background="@color/colorPrimary" 
  android:minHeight="45dp" 
  android:orientation="horizontal" 
  android:gravity="center_vertical" 
  > 
  <ImageButton 
   android:id="@+id/home_left_scan" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:paddingRight="19dp" 
   android:paddingTop="3dp" 
   android:paddingBottom="3dp" 
   android:paddingLeft="11dp" 
   android:layout_centerVertical="true" 
   android:background="#00000000" 
   /> 
  <com.zhangqie.searchbox.view.DrawableTextView 
   android:id="@+id/home_search" 
   android:layout_width="match_parent" 
   android:layout_height="28dp" 
   android:layout_weight="1" 
   android:background="@drawable/search_view_background" 
   android:gravity="center_vertical" 
   android:maxLines="1" 
   android:text="輸入搜索相關(guān)內(nèi)容" 
   android:drawableLeft="@mipmap/icon_search" 
   android:textSize="12sp" 
   android:drawablePadding="11dp" 
   /> 
  <ImageButton 
   android:id="@+id/home_right_more" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_centerVertical="true" 
   android:layout_alignParentRight="true" 
   android:paddingRight="15dp" 
   android:paddingTop="3dp" 
   android:paddingBottom="3dp" 
   android:paddingLeft="15dp" 
   android:background="#00000000" 
   /> 
 </LinearLayout> 

自定義DrawableTextView:(文字圖標(biāo)居中)

public class DrawableTextView extends TextView { 
 public DrawableTextView(Context context, AttributeSet attrs, 
       int defStyle) { 
  super(context, attrs, defStyle); 
 } 
 public DrawableTextView(Context context, AttributeSet attrs) { 
  super(context, attrs); 
 } 
 public DrawableTextView(Context context) { 
  super(context); 
 } 
 @Override 
 protected void onDraw(Canvas canvas) { 
  Drawable[] drawables = getCompoundDrawables(); 
  // 得到drawableLeft設(shè)置的drawable對(duì)象 
  Drawable leftDrawable = drawables[0]; 
  if (leftDrawable != null) { 
   // 得到leftDrawable的寬度 
   int leftDrawableWidth = leftDrawable.getIntrinsicWidth(); 
   // 得到drawable與text之間的間距 
   int drawablePadding = getCompoundDrawablePadding(); 
   // 得到文本的寬度 
   int textWidth = (int) getPaint().measureText(getText().toString().trim()); 
   int bodyWidth = leftDrawableWidth + drawablePadding + textWidth; 
   canvas.save(); 
   canvas.translate((getWidth() - bodyWidth) / 2, 0); 
  } 
  super.onDraw(canvas); 
 } 
} 

有需要的朋友點(diǎn)擊下載源碼哦!

https://github.com/DickyQie/android-basic-control/tree/search-box

總結(jié)

以上所述是小編給大家介紹的Android 改變圖標(biāo)原有顏色和搜索框的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

  • Android中自定義Window Title樣式實(shí)例

    Android中自定義Window Title樣式實(shí)例

    這篇文章主要介紹了Android中自定義Window Title樣式實(shí)例,本文給出效果預(yù)覽和實(shí)現(xiàn)方法,需要的朋友可以參考下
    2015-01-01
  • 百度語音識(shí)別(Baidu Voice) Android studio版本詳解

    百度語音識(shí)別(Baidu Voice) Android studio版本詳解

    這篇文章主要介紹了百度語音識(shí)別(Baidu Voice) Android studio版本詳解的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • Android 實(shí)現(xiàn)把bitmap圖片的某一部分的顏色改成其他顏色

    Android 實(shí)現(xiàn)把bitmap圖片的某一部分的顏色改成其他顏色

    這篇文章主要介紹了Android 實(shí)現(xiàn)把bitmap圖片的某一部分的顏色改成其他顏色,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • Android實(shí)現(xiàn)檢測(cè)實(shí)體按鍵事件并屏蔽

    Android實(shí)現(xiàn)檢測(cè)實(shí)體按鍵事件并屏蔽

    這篇文章主要介紹了Android實(shí)現(xiàn)檢測(cè)實(shí)體按鍵事件并屏蔽 ,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Android ormlite更改數(shù)據(jù)庫默認(rèn)位置

    Android ormlite更改數(shù)據(jù)庫默認(rèn)位置

    本文主要介紹Android ormlite,這里提供實(shí)例代碼并詳細(xì)說明了 ormlite更改數(shù)據(jù)庫默認(rèn)位置,有需要的朋友可以參考下
    2016-07-07
  • Android Studio 超級(jí)簡(jiǎn)單的打包生成apk的方法

    Android Studio 超級(jí)簡(jiǎn)單的打包生成apk的方法

    本篇文章主要介紹了Android Studio 超級(jí)簡(jiǎn)單的打包生成apk的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android實(shí)現(xiàn)漂亮的Gallery畫廊

    Android實(shí)現(xiàn)漂亮的Gallery畫廊

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)漂亮的Gallery畫廊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • Android實(shí)現(xiàn)圖片點(diǎn)擊放大

    Android實(shí)現(xiàn)圖片點(diǎn)擊放大

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圖片點(diǎn)擊放大,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Android中 TeaScreenPopupWindow多類型篩選彈框功能的實(shí)例代碼

    Android中 TeaScreenPopupWindow多類型篩選彈框功能的實(shí)例代碼

    這篇文章主要介紹了Android TeaScreenPopupWindow多類型篩選彈框功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2019-06-06
  • 最新評(píng)論

    青海省| 远安县| 安化县| 石景山区| 色达县| 壤塘县| 南阳市| 门源| 巫山县| 公安县| 疏附县| 于都县| 尼木县| 昭苏县| 页游| 疏附县| 青阳县| 北流市| 睢宁县| 科尔| 城步| 雷山县| 永登县| 金华市| 西畴县| 甘孜县| 沁阳市| 施甸县| 吉木萨尔县| 都昌县| 营山县| 保德县| 太和县| 齐齐哈尔市| 桦南县| 淮北市| 怀仁县| 泰安市| 阿克| 保德县| 邻水|