發表文章

目前顯示的是 11月, 2020的文章

解決Window10的cmd下找不到react-native指令

雖然Window10的cmd下找不到react-native指令,但是npm, node, yarn等等都可以用,我主要是使用yarn開發react-native。我也不知道甚麼時候開始有這個問題的,只知道系統剛灌好沒有這個問題。 羅列一些yarn的指令 查看help $ yarn --help 查看yarn已安裝在系統層級的套件 $ yarn global list yarn global v1.22.5 info "react-native-cli@2.0.1" has binaries:    - react-native 查看yarn系統層級的套件目錄 $ yarn global dir C:\Users\{使用者名稱}\AppData\Local\Yarn\Data\global 查看yarn系統層級的執行檔目錄 $ yarn global bin C:\Users\{使用者名稱}\AppData\Local\Yarn\bin 解決找不到react-native指令 查看yarn系統層級的執行檔目錄 將該目錄加入你的環境變數PATH 重啟cmd 完工 如果是其他作業系統可以參考下面這篇加入你的PATH https://stackoverflow.com/questions/43501514/how-to-display-yarn-globally-installed-packages Windows: %LOCALAPPDATA%/Yarn/config/global OSX and Linux non-root: ~/.config/yarn/global Linux if logged in as root: /usr/local/share/.config/yarn/global

Android App跳出Alert對話框

Android App跳出Alert對話框範例Code如下:  設定中間的按鈕 setNeutralButton 設定左邊的按鈕 setPositiveButton 設定右邊的按鈕 setNegativeButton 實際上positive是用以表示"同意", negative是用以表示"反對"或"取消", 跟左右邊沒有直接關係, 所以在有些裝置的主題上, 這個按鈕的左右邊位置會是反的,  不用覺得太驚訝。 參考:  http://toimy.blogspot.tw/2010/08/android-alertdialog.html 2020-11-02補充: 如果你遭遇以下錯誤可以把AlertDialog.Builder的建構子參數,從getContext()改成this即可 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. AlertDialog alertDialog = new AlertDialog.Builder( this ).create(); 或是如果你要顯示的Activity是MainActivity的話 AlertDialog alertDialog = new AlertDialog.Builder( MainActivity.this ).create(); 這裡的問題是因為 Android內建的android.app.AlertDialog.Builder跟android.support.v7.app.AlertDialog的AlertDialog.Builder不太一樣所致 https://developer.android.com/reference/android/app/AlertDialog.Builder 另外,還有套用theme的寫法 new AlertDialog.Builder(MainActivity.this, R.style.Theme_AppCompat_Light_Dialog_Alert) 參考: https://givemepass.blogspot.com/2015