android小細節

<style name="Theme.Translucent.NoTitleBar">
    <item name="windowNoTitle">true</item>
    <item name="windowContentOverlay">@null</item>
</style>

1.在引導頁加上以上代碼,可以一開始就顯示背景圖,而不顯示白色背景。

以及去除引導頁title.


2.ListView

android:clipToPadding用於ListView滑動時忽略padding。



3.actionBar更改返回圖標的方法:

1.要求API版本大於18

  ActionBar ab = getSupportActionBar();
  ab.setDisplayHomeAsUpEnabled(true);
  ab.setHomeAsUpIndicator(R.drawable.ic_menu);
2.更改樣式

在style.xml文件中新增樣式

<style name="style_normal" parent="Theme.AppCompat.Light">  
        <item name="android:homeAsUpIndicator">@drawable/back</item> <!--返回icon-->  
 </style> 

然後在Activity中使用該樣式


4.Toast頻繁顯示

可以自己實現幫助類,每次使用Toast都是對同一個Toast進行設置

public class ToastHelper {
    public static Toast toast = null;

    public static void showToast(Context context,String content,int duration){
        if(toast == null){
            toast = Toast.makeText(context,content,duration);
        }else{
            toast.setText(content);
            toast.setDuration(duration);
        }
        toast.show();
    }

    public static void cancelToast(){
        if(toast != null){
            toast.cancel();
        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章