收集網上看到,或者自己總結的tips
view.isShown ()
當view本身以及它的所有祖先們都是visible時,isShown()才返回TRUE。
而平常我們調用if(view.getVisibility() == View.VISIBLE)
只是對view本身而不對祖先的可見性進行判斷android.text.format.Formatter
方法 :public static String formatFileSize(Context context, long number)
number 的單位是B,返回如:3.33MB (B->KB->MB->GB->TB->PB)
<!-- Suffix added to a number to signify size in bytes. -->
<string name="byteShort">B</string>
<!-- Suffix added to a number to signify size in kilobytes. -->
<string name="kilobyteShort">KB</string>
<!-- Suffix added to a number to signify size in megabytes. -->
<string name="megabyteShort">MB</string>
<!-- Suffix added to a number to signify size in gigabytes. -->
<string name="gigabyteShort">GB</string>
<!-- Suffix added to a number to signify size in terabytes. -->
<string name="terabyteShort">TB</string>
<!-- Suffix added to a number to signify size in petabytes. -->
<string name="petabyteShort">PB</string>
-
android.media.ThumbnailUtils
類,用來獲取媒體(圖片、視頻)縮略圖 -
String.format(String format, Object... args)
與Context.getString(int resId, Object... formatArgs)
用于格式化strings.xml中的字符串 -
TextView.append(CharSequence text)
和append(CharSequence text, int start, int end)
方法,直接在Textview后面追加字符串 -
DecimalFormat
類,用于字串格式化包括指定位數、百分數、科學計數法等 -
android.util.Pair
類,封裝了兩個對象的類(用處自己想吧)
public Pair(F first, S second) {
this.first = first;
this.second = second;
}
- 安卓的單元測試類
ApplicationTestCase<Application>
自帶mContext屬性,InstrumentationTestCase
可以跳轉到一個Activity進行測試 - Android 軟鍵盤蓋住輸入框或者布局的解決辦法
- 方法一:在你的activity中的oncreate中setContentView之前寫上這個代碼'getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);'
- 方法二:在項目的AndroidManifest.xml文件中界面對應的<activity>里加入
android:windowSoftInputMode="stateVisible|adjustResize"
,這樣會讓屏幕整體上移。如果加上的是android:windowSoftInputMode="adjustPan"
這樣鍵盤就會覆蓋屏幕。 - TextView的標準字體
style="@style/TextAppearance.AppCompat.Display4"
style="@style/TextAppearance.AppCompat.Display3"
style="@style/TextAppearance.AppCompat.Display2"
style="@style/TextAppearance.AppCompat.Display1"
style="@style/TextAppearance.AppCompat.Headline"
style="@style/TextAppearance.AppCompat.Title"
style="@style/TextAppearance.AppCompat.Subhead"
style="@style/TextAppearance.AppCompat.Body2"
style="@style/TextAppearance.AppCompat.Body1"
style="@style/TextAppearance.AppCompat.Caption"
style="@style/TextAppearance.AppCompat.Button"
樣式效果
android:clipToPadding
控件的繪制區域是否在padding里面。默認為true。如果你設置了此屬性值為false,可以實現 ListView頂部默認有一個間距,向上滑動后,間距消失。(PS:如果使用margin或padding,都不能實現這個效果。加一個headerView又顯得大材小用,而且過于麻煩。此處的clipToPadding配合paddingTop效果就剛剛好。)類似上面
android:clipChildren
的意思:否限制子View在其范圍內。在做動畫或者一些特別的布局是會起到非常神奇的作用-
Android5.0以后Theme的一些顏色
CountDownTimer
可以用于倒計時通過Calendar獲得第幾周的周幾
final int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
final int dayOfWeekInMonth = calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH);
- 在layout.xml中設置RecyclerView.setLayoutManager()
xml布局文件
to be continue...