mymombehindme
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    2
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: XML --- # XML ## 如何排版,熟用XML - 每個XML文件都由XML序言開始,在前面的代碼中的第一行就是XML序言,<?xml version="1.0"?>。這一行代碼會告訴解析器或瀏覽器這個檔案應該按照XML規則進行解析 - Res介紹 - 在程式架構區中,有一個資料夾是”res”,是resource的簡寫,這個資料夾主要是處理APP的靜態檔案以便使用,其下有分屬不同功能的資料夾,分別功能如下, - res/anim (放置動畫,支援xml定義的動畫檔) - res/drawable (放置圖片,支援png檔,jpg檔以及xml產生的向量圖) - res/mipmap (放置圖片,支援png檔,jpg檔,可以只使用上面的drawable資料夾即可) - res/layout (放置Layout,用xml排版出來的UI都放這邊) - res/values (比較雜亂一點,舉凡顏色,語言文字,主題都可以放這邊) - res/raw (放置其他檔案,沒有特別支援的檔案格式,需要靠自己去讀檔與解析內容) - ![](https://i.imgur.com/4N2bIP9.png) - 這裏代表在最外層我們用一個LinearLayout包起來,在LinearLayout裡面我們放入了兩個View,分別是TextView以及Button。這裏我們可以看得出來XML是一種巢狀式的結構,有助於我們在排版的時候針對一些細節在各個Layout間做調整。 --- ## LinearLayout(线性布局) - ![](https://i.imgur.com/tlLQzvK.png) - ### link - https://www.runoob.com/w3cnote/android-tutorial-linearlayout.html ## 雜(java + xml) - 然後要使用strings.xml的代號也很簡單,Android都會編譯到R裡面,在xml呼叫用 @string/bmi_hello 即可在java呼叫要用 R.string.bmi_hello,不過要轉換成String才能正常使用 getText(R.string.bmi_hello), - https://developer.android.com/reference/packages(java for android API) ## Bundle - Bundle型別正是我們前面所導入的package之一,Bundle的內容與Android手機平臺的記憶體管理有關。 - Bundle類別可以保存Activity上一次關閉(stop)時的狀態,我們可以透過覆載onStop方法來保存關閉前的狀態,當程式啟動時,會再次呼叫onCreate方法,就能從savedInstanceState中得到前一次凍結的狀態。我們也可以透過Bundle來將這個Activity的內容傳到下一個Activity中 - Bundle 主要用於資料傳遞,主要是以key-value方式來儲存資料。代碼如下: - //實例化一個Bundle物件 Bundle bundle = new Bundle(); //儲存資料 第一個為參數key,第二個為Value bundle.putString("key","Value"); bundle.putString("name","learnexp"); intent.putExtras(bundle); // 記得put進去,不然資料不會帶過去哦 - ## super.onCreate(savedInstanceState); - super是關鍵字,代表這個MainActivity類別的上層類別AppCompatActivity,意思是執行AppCompatActivity類別中onCreate方法的內容,一個Android應用程式,會對應到一個以上的Activity,onCreate方法是每個Activity類別初始化時都會去呼叫的方法 - 因為我們已經覆載(@Override)了MainActivity類別的onCreate方法,因此如果我們想將原本的onCreate方法內容保留,再加上我們自己的內容,就要使用super語句,並傳入savedInstanceState參數。如此就會先執行AppCompatActivity類別的onCreate方法,再執行我們覆載的onCreate方法裡面的其他程式內容。 - ## setContentView(R.layout.activity_main); - 螢幕顯示的畫面,是透過各種介面元件的排列配置結構來描述的。要將一套版面配置的層次結構轉換到一個螢幕上時,Activity會呼叫它用來設定螢幕顯示內容的setContentView方法,並傳入定義了版面配置的Xml描述檔。當Activity被啟動並需要顯示到螢幕上時,系統會通知Activity並根據引用的Xml檔來描繪出使用者介面。 - 為了要取得Button物件要import android.widget.Button; - 為了要取得EditText物件要import android.widget.EditText; - 為了要取得TextView物件要import android.widget.TextView; - 呼叫 findViewByID() 方法,即可在執行時期「動態取得 View 物件」 - java.lang.Double.parseDouble() 方法返回初始化為指定字符串的一個新的double表示的值,因為使用了Double類的valueOf方法 - ## final - 成員 (member) 宣告時若使用關鍵字 final 修飾,表示該成員為常數 (constant) ,屬性 (field) 或區域變數 (local variable) 都不能重新給值,而方法 (method) 繼承 (inherit) 後不可被改寫 (override) 。 - ## Intent - Intent代表使用者與應用程式的互動,互動通常會產生變化,例如按下一個圖示後進行撥出電話,或者按下一個按鈕後轉換到另一個畫面(也就是另一個Activity)。使用android.content.Intent類別可以達到這些功能,Intent類別的建構子有很多種,其中常用來轉換Activity的建構子規格如下: - intent(意圖),轉換畫面 - Intent intent = new Intent(); intent.setClass(MainActivity.this,Test.class); //告訴它從哪邊切換到哪邊 startActivity(intent);//切換 or Intent intent = new Intent(MainActivity.this,Test.class); startActivity(intent);//切換 ## RelativeLayout - 顧名思義就是可以透過相對位置來設定布局內各個元件的位置,其元件設定的位置可以是相對於整個RelativeLayout布局或者是相對於其他元件的位置。 - link - https://fiend1120.pixnet.net/blog/post/191809863 ## ImageView - 常用屬性 - 加載網路圖片 ## android API - link: - https://stuff.mit.edu/afs/sipb/project/android/docs/reference/android/view/View.OnTouchListener. ## orientation - android:orientation="垂直:vertical/水平:horizontal" Orientation : 決定版面呈現水平或垂直。 ## Toast - Toast是一個滿好用的東西,會在畫面上彈出一個短暫訊息,而且不會影響Activity處理程序,當時間到達時Toast會自動消失(預設2、3.5秒),它能拿來當作一些簡單訊息的傳遞,例如「密碼錯誤」、「您點擊了XX選項」等等,是一個非常實用的功能。 - public static Toast makeText (Context context, CharSequence text, int duration) 第一個參數 Context :應用程式的Context 第二個參數 CharSequence :要顯字的訊息文字 第三個參數 duration :Toast的顯示持續時間,這邊官方只提供兩個選擇 Toast.LENGTH_SHORT持續2秒 Toast.LENGTH_LONG 持續 3.5秒 ## android:src = "@drawable/icon" - src代表source,@代表引用,意思就是使用drawable文件夹中的icon这个图片作为你当前使用的图片。 ## app:showAsAction - 1.always:总是显示在界面上 - 2.never:不显示在界面上,只让出现在右边的三个点中 - 3.ifRoom:如果有位置才显示,不然就出现在右边的三个点中 ## android:showAsAction - 1.alaways:这个值会使菜单项一直显示在ActionBar上。 - 2.ifRoom:如果有足够的空间,这个值会使菜单显示在ActionBar上。 - 3.never:这个值菜单永远不会出现在ActionBar是。 - 4.withText:这个值使菜单和它的图标,菜单文本一起显示。 ## onCreateOptionsMenu - 新增選單 - add()方法的四個引數,依次是: 1、組別,如果不分組的話就寫Menu.NONE, 2、Id,這個很重要,Android根據這個Id來確定不同的選單 3、順序,哪個選單項在前面由這個引數的大小決定 4、文字,選單項的顯示文字 add()方法返回的是MenuItem物件,呼叫其setIcon()方法,為相應MenuItem設定Icon 示例: public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); menu.add(Menu.NONE, Menu.First 1, 0, "設定").setIcon(R.drawable.setting); return true; } - 佈局檔案新增: getMenuInflater().inflate(R.menu.options_menu, menu); 呼叫Activity的getMenuInflater()得到一個MenuInflater, 使用inflate方法來把佈局檔案中的定義的選單 載入給 第二個引數所對應的menu物件 示例: @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.options_menu, menu); return true; } - 選單項監聽: - 只要選單中的選單項被點選,都會觸發onOptionsItemSelected(MenuItem item) item引數即為被點選的選單項,那麼需要在此方法內判斷哪個Item被點選了,從而實現不同的操作。對於兩種不同的新增選單方法,判斷的方法有一點區別,但本質是一樣的。 - 佈局檔案新增選單的判斷方法: @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); switch(item.getItemId())//得到被點選的item的itemId { case R.id.menu_setting://這裡的Id就是佈局檔案中定義的Id,在用R.id.XXX的方法獲取出來 break; case R.id.menu_info: break; } return true; } ## android:orderInCategory - 當中orderInCategory可以調整menu內的順序, 數字越小的在越前面 ## AlertDialog.Builder - link - https://codertw.com/android-%E9%96%8B%E7%99%BC/350617/ - 在程式中加入選單 ## android Activity(活動) - Android的虛擬機(VM)是使用堆疊(Stack based)管理,主要有四種狀態 - Active(活動) - Active狀態是使用者啟動應用程式或Activity後,Activity運行中的狀態 - 在Android平臺上,同一個時刻只會有一個Activity處於活動(Active)或運行(Running)狀態。其他的Activity都處於未啟動(Dead)、停止(Stopped)、或是暫停(Pause)的狀態 - pause(暫停) - Pause狀態是目前運行的螢幕畫面暫時暗下來,退到背景畫面的狀態 - 當我們使用Toast、Alerting或是電話來了時,都會讓原本運行的Activity退到背景畫面。新出現的Toast、AlertDialog等介面元件蓋住了原來的Activity畫面。Activity處在Paused狀態時,使用者無法與原Activity互動 - stop(停止) - Stopped狀態是當有其他Activity正在執行,而這個Activity已經交出螢幕控制權,處於不再動作的狀態 - 透過長按Home鈕,可以叫出所有處於Stopped狀態的應用程式列表,點選後即再次啟動該應用程式 - Dead(已回收或未啟動) - Dead狀態是Activity尚未被啟動、已經被手動停止,或已經被系統回收的狀態。 - 要手動終止Activity,可以在程式中呼叫finish函式。如果是被系統回收,可能是因為記憶體不足了,所以系統根據記憶體不足時的回收規則,將處於Stopped狀態的Activity所佔用的記憶體回收 - 系統記憶體不足時的行為: - 先回收與其他Activity或Service/Intent Receiver無關的行程(即優先回收獨立的Activity) - 再回收處於Stopped狀態的其他類型Activity(在背景等待的Activity)。最久沒有使用的Acitvity優先回收(官方說法是「根據LRU演算法...」) - 還不夠?回收service行程 - 快不行啦!關掉可見的Activity/行程 - 關閉當前的Activity - 當系統缺記憶體缺到開始砍 可見的Activity/行程 時,表示早就應該要換手機了。 - 程式共有七個生命週期狀態,其中又可以歸納為三類 - 資源分配 (Create / Destroy) - 完整的Activity生命週期由Create狀態開始,由Destroy狀態結束。建立Create時分配資源,銷毀Destroy時釋放資源 - 可見與不可見 (Start / ReStart / Stop) - 當Activity運行到Start狀態時,就可以在螢幕上看到這個Activity,相反地,當Activity運行到Stop狀態時,這個Activity就會從螢幕上消失 - 當Activity尚未被銷毀Destroy,而又再次被呼叫時,就會先進入ReStart狀態後,在進入正常的Start狀態。例如我們從當前的Activity返回前一個Activity時,將會比直接開啟新Activity多進入一個Restart狀態。 - 是否有螢幕控制權 (Resume / Pause) - 當使用者預備離開目前頁面時,原來的Activity會進入Pause狀態,暫時放棄直接存取螢幕的能力,被中斷到背景去,將前景交給優先級高的事件。當這些優先級高的事件處理完後,Activity又改進入Resume狀態,取回了螢幕控制權。 - ![](https://i.imgur.com/FWORj0m.png) - 呼叫另一個Activity - onPause (1) → onCreate (2) → onStart (2) → onResume (2) → onStop (1) - 這是個先凍結原本的Activity,再交出螢幕控制權(Pause狀態)的過程。直到Activity 2完成一般啟動流程後,Activity 1 才會被停止 - ![](https://i.imgur.com/UQpBb5Z.png) - 返回原Activity - onPause (2) → onRestart (1) → onStart (1) → onResume (1) → onStop (2) → onDestroy (2) - 在新的Activity中,點選硬體的Back 按鈕,可以讓我們回到原本的Acitvity ## Android Intent&Bundle 傳遞資料(包含傳遞自定義物件) - link: - https://cookiesp.pixnet.net/blog/post/84190702 ## “import android.support.v7.app.ActionBarActivity;”Code Answer - ![](https://i.imgur.com/ay2Svlf.png) ## fill_parent、wrap_content和match_parent的区别和作用 - link: https://blog.csdn.net/Biegral/article/details/46373219 ## xml 顏色 - link: https://blog.xuite.net/saso0704/wretch/203137609 ## 約束佈局ConstraintLayout - link: https://www.itread01.com/chklif.html - 如果行不通,用這篇解答 - link:https://stackoverflow.com/questions/57903216/didnt-find-class-androidx-constraintlayout-constraintlayout - 注意事項: - https://www.itread01.com/content/1548133593.html ## 資料視覺化 - link:https://github.com/AnyChart/AnyChart-Android ## Textview - link: - https://ithelp.ithome.com.tw/articles/10189268 ## Fragment - link: - https://androidstation.pixnet.net/blog/post/227190520 - https://xnfood.com.tw/fragment/ 靜態 - https://xnfood.com.tw/fragment02/ 動態 ## Navigation Component - link: - https://ithelp.ithome.com.tw/articles/10215160 ## RecyclerView - link: - https://ithelp.ithome.com.tw/articles/10187949 ## android studio連接到資料庫 - link: - https://mnya.tw/cc/word/1480.html ## java getstring - link: - https://www.itread01.com/content/1547960239.html ## Com.Mysql.Cj.Jdbc.Exceptions.CommunicationsException: Communications Link Failure - link: - https://facingissuesonit.com/2019/05/07/com-mysql-cj-jdbc-exceptions-communicationsexception-communications-link-failure/ ## JDBC ResultSet 介面的公用方法。 - link: - https://www.ibm.com/support/knowledgecenter/zh-tw/SSGU8G_11.70.0/com.ibm.tms.doc/ids_tms_272.htm - findColumn | int findColumn (java.lang.String columnName) | 擷取 columnName 的直欄索引。 - isAfterLast | boolean isAfterLast() | 決定時間序列游標是否在最後一個元素之後。 ## menu監聽事件 - https://www.ruyut.com/2018/12/android-studio-onoptionsitemselected.html ## android studio 小訣竅 - ctrl+O = 可選擇要覆寫什麼

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully