跳到主要內容

發表文章

目前顯示的是 10月, 2017的文章

Android using BottomNavigationView

Creating Navigation Menu menu_navigation.xml <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/action_home" android:icon="@drawable/ic_home" android:title="@string/action_home"/> <item android:id="@+id/action_profile" android:icon="@drawable/ic_person" android:title="@string/action_profile"/> <item android:id="@+id/action_settings" android:icon="@drawable/ic_settings" android:title="@string/action_settings"/> </menu> Creating Layout main_activity.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://

Material Design - TabLayout widget and ViewPager using Fragments.

TabLayout widget and ViewPager using Fragments.  Layout res/layout/content_viewpager.xml <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".TabLayoutActivity" tools:showIn="@layout/activity_tab_layout"> <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintTop

Material Design - RecyclerView and AppBarLayout

GitHub RecyclerView RecyclerView 小工具是比較進階和彈性的 ListView 版本。 這個小工具是一個用來顯示大型資料集的容器,只要維護少數幾個視圖,就可極有效率地捲動資料集。您的資料集元素在執行階段會根據使用者操作動作或網路事件而變更。 RecyclerView 類別會提供下列項目,簡化大型資料集的顯示和處理方式: 版面配置管理員,用來將項目定位 (將它設為橫向或直向,或者以網格形式顯示) 常見項目操作 (例如移除或新增項目) 的預設動畫  CoordinatorLayout 也只支援 RecyclerView 而不支援 LisView RecyclerView 架構,比 ListView多了一個LayoutManager 如果要使用 RecyclerView 小工具,您必須指定配接器和版面配置管理員。 如要建立配接器,請延伸 RecyclerView.Adapter 類別。 RecyclerView 提供下列內建的版面配置管理員: LinearLayoutManager 在垂直或水平捲動清單中顯示項目。 GridLayoutManager 會在網格中顯示項目。 StaggeredGridLayoutManager 會在交錯網格中顯示項目。 如要建立自訂版面配置管理員,請延伸 RecyclerView.LayoutManager 類別。 Material Design-AppBarLayout AppBar 最初叫 ActionBar,後來改名為 Toolbar ,現在統稱叫 AppBar。 AppBarLayout 即是控制內容元件滑動時 AppBar 的顯示,需要在 CoordinatorLayout 底下才能運作。可輕易做到滑動 RecyclerView 時,自動顯示和隱藏 ToolBar CollapsingToolbarLayout 它是 AppBarLayout 中唯一的child,而它的 child view 可加上 layout_collapseMode 去決定 CollapsingToolBarLayout 被隱藏時他們自身的顯示情況。 最常見的用法是在滑動時將一個大圖和文字的 AppBar 縮為純文字。 設定Layout &l

Material Design - Card View and Recycler View

build.gradle (Module.app) 添加CardView,RecyclerView和Glide依賴關係。  RecyclerView用於以網格方式顯示相冊。  CardView用於顯示單個專輯項目。  Glide用於顯示專輯封面圖片。 dependencies {      //CardView     compile 'com.android.support:cardview-v7:25.3.1'     //RecyclerView     compile 'com.android.support:recyclerview-v7:25.3.1'     //Glide ImageLoader....     compile 'com.github.bumptech.glide:glide:3.7.0' } 將以下字符串,顏色和調整資源添加到strings.xml,colors.xml和dimensions.xml文件。 string.xml <resources> <string name="app_name">Card View</string> <string name="action_settings">Settings</string> <string name="action_add_favourite">Add to Favourites</string> <string name="action_play_next">Play Next</string> <string name="backdrop_title">LOVE MUSIC</string> <string name="backdrop_subtitle">This season top 20 albums</string> </resources>

Material Design - CoordinatorLayout & FlationActionBar & Snackbar

  Meterial Design - Floating Action Button 需要在build.gradle 加入 compile 'com.android.support:design:25.3.1' elevation 陰影高度 pressedTranslationZ按下的時候陰影就會增大 <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:elevation="6dp" app:pressedTranslationZ="12dp" android:clickable="true" app:backgroundTint="@color/purpleColorPrimary" app:rippleColor="@color/colorAccent" app:fabSize="normal" app:srcCompat="@android:drawable/ic_input_add" android:layout_gravity="bottom|end"/> Meterial Design - Snackbar Snack bar 跟 Toast 不同的是,Snack bar 是以 view 作參數,而不是以 context Snackbar.make(contentV

Material Design - Navigation Drawer & Toolbar

GitHub Creating a Navigation Drawer 在您決定在應用程序中使用導航抽屜之前,您應該了解 導航欄設計指南 中定義的用例和設計原則。 DrawerLayout 用來做從左到右拉出來的抽屜效果。 NavigationView 用來在拉出來的畫面上,顯示用戶資料和導覽選單。 安裝 Android Design Support Library 可通過 Gradle 來安裝: dependencies { compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:design:25.3.1' } 準備 AndroidManifest.xml 設定主題使用 android:theme @sytle/MyAppTheme。 res/values/style.xml 新增 MyAppTheme Style <style name="MyAppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">#d90505</item> <item name="colorPrimaryDark">@color/colorAccent</item> <item name="android:windowActionBar">false</item> <!--ActionMode可以覆蓋在Toolbar上面 --> <item name="android:windowActionModeOverlay">true</item> <item name="android:windowDrawsSystemBarBackgrounds"