Android-技巧二

1、教程Markdown

在線網(wǎng)址, 動態(tài)權(quán)限授權(quán)示例.

2、在線視頻剪切網(wǎng)站

非常不錯的在線網(wǎng)站, 處理音頻和視頻. 參考.

3、 Android測試工具

推薦兩個常用的測試工具EspressoRobolectric.

4、TextView的標(biāo)準(zhǔn)字體

樣式

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"
Paste_Image.png

5、透明statusbar和全屏ImageView

status bar設(shè)置成為透明顏色.

<style name="AppTheme.NoStatusBar"> 
<item name="android:windowTranslucentStatus">true</item> </style>

頁面的根布局是CollapsingToolbarLayout

style="@style/TextAppearance.AppCompat.Button"<android.support.design.widget.CollapsingToolbarLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@null"
        android:fitsSystemWindows="true"
        android:scaleType="centerCrop"
        android:src="@drawable/christmas"/>
</android.support.design.widget.CollapsingToolbarLayout>

GitHub標(biāo)簽

網(wǎng)址, 比如:


6. dp和sp的區(qū)別

dp是Android頁面常用的度量單位, sp主要用于字體度量.
在標(biāo)準(zhǔn)情況下, dp等于sp. 然而, Android系統(tǒng)允許用戶設(shè)置字體大小, sp會隨著字體的大小而改變, 放大或是縮小.
設(shè)置位置(紅米): Android -> 設(shè)置 -> 字體大小 -> 標(biāo)準(zhǔn)(默認)或大小號.

7、顯示Activity棧的Shell命令

adb shell dumpsys activity | sed -n -e '/Stack #/p' -e '/Running activities/,/Run #0/p'

8、修改string的顏色

在 Android 開發(fā)中,通常會吧文本放在 strings.xml 文件中,然后再引用。

有時候,有些需求需要修改文本中的部分字的字體顏色,可以用以下方式修改:

修改原本的strings.xml:

<string name="hh_no_order"><Data><![CDATA[sorry,沒有任何訂單,<font color="#fc2a56">前往買買買</font>]]></Data></string>

代碼中的使用需要配合Html.fromHtml(),如:

mTvTip.setText(Html.fromHtml(mTips))

Android log colors

  • To do so
  • In toolbar menu select File|Settings
  • Choose Editor|Colors & Fonts|Android Logcat
  • Click on Save As… button and create new color schema
  • Change all colors to ‘Holo theme colors’ (Uncheck ‘Use inherited attributes’ for every color)
Assert:  #AA66CC
Debug:   #33B5E5
Error:   #FF4444
Info:    #99CC00
Verbose: #FFFFFF
Warning: #FFBB33

移除默認的 Window 背景

一般應(yīng)用默認繼承的主題都會有一個默認的 windowBackground ,比如默認的 Light 主題:
在 BaseActivity 的 onCreate() 方法中使用下面的代碼移除:

getWindow().setBackgroundDrawable(null);
// 或者
getWindow().setBackgroundDrawableResource(android.R.color.transparent);

ImageView的background和imageDrawable重疊

Android中,所有的view均可以設(shè)置background。ImageView除了能夠設(shè)置background之外,還能設(shè)置ImageDrawable。

在開發(fā)中,很多時候需要顯示圖片,在圖片加載出來之前通常是需要顯示一張默認圖片的,很多時候會使用ImageView的background屬性來設(shè)置默認背景圖,而imageDrawable來設(shè)置需要加載的圖片。這樣會導(dǎo)致一個問題,當(dāng)圖片加載到頁面后,默認背景圖被擋住了,但是卻任然需要繪制,導(dǎo)致過渡繪制情況的發(fā)生。

copyright 年份

<string name="copyright">Copyright ? 2016-%d mrwu</string>

 int year = Calendar.getInstance().get(Calendar.YEAR);
        tvCopyright.setText(getString(R.string.copyright, year));

Live template

android.content.SharedPreferences sharedPreferences =getPreferences(Context.MODE_PRIVATE);
android.content.SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(getString(R.string.$stringVal$), $spVal$);
editor.apply();

Snackbar.make($view$,“$text$”,Snackbar.LENGTH_LONG)
.setAction(“Action”, null).show();

原文:
https://medium.com/google-developer-experts/configuring-android-studio-4aa4f54f1153
http://blog.csdn.net/a740169405

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容