This video show how to apply Android provided Material Theme to your Activity.
- Edit values/styles.xml to add a new style inherits from Android provided Material Theme: android:Theme.Material, android:Theme.Material.Light or android:Theme.Material.Light.DarkActionBar.
- Edit AndroidManifest.xml to use the new style.
- You have to change your MainActivity extends Activity. Otherwise the following error will happen: You need to use a Theme.AppCompat theme (or descendant) with this activity. The video also show how it display on Multi-Window Mode.
seekBarZ1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { image1.setZ(i); } }
@Override public void onStartTrackingTouch(SeekBar seekBar) {}
@Override public void onStopTrackingTouch(SeekBar seekBar) {} });
seekBarZ2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { text2.setZ(i); text2.setText("elevation: " + String.valueOf(i) + "px"); } }
@Override public void onStartTrackingTouch(SeekBar seekBar) {}
@Override public void onStopTrackingTouch(SeekBar seekBar) {} }); } }
seekBarZ.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { image.setZ(i); } }
@Override public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override public void onStopTrackingTouch(SeekBar seekBar) {
With the help from the Android Design Support Library, you can implement a number of important material design components to all developers and to all Android 2.1 or higher devices.
This example show how to implement Bottom Sheets with help of Android Design Support Library.
/* Build.VERSION.SDK_INT: The user-visible SDK version of the framework; its possible values are defined in Build.VERSION_CODES. https://developer.android.com/reference/android/os/Build.VERSION_CODES.html */ int sdk_int = Build.VERSION.SDK_INT;
backgroundLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switch (bottomSheetBehavior.getState()){ case BottomSheetBehavior.STATE_COLLAPSED: bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); break; case BottomSheetBehavior.STATE_EXPANDED: bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); break; } } });
}
BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback(){ @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { switch (newState){ case BottomSheetBehavior.STATE_COLLAPSED: textPrompt.setText("COLLAPSED"); break; case BottomSheetBehavior.STATE_DRAGGING: textPrompt.setText("DRAGGING"); break; case BottomSheetBehavior.STATE_EXPANDED: textPrompt.setText("EXPANDED"); break; case BottomSheetBehavior.STATE_HIDDEN: textPrompt.setText("HIDDEN"); break; case BottomSheetBehavior.STATE_SETTLING: textPrompt.setText("SETTLING"); break; default: textPrompt.setText("unknown..."); } }
@Override public void onSlide(@NonNull View bottomSheet, float slideOffset) {
@Override publicbooleanonCreateOptionsMenu(Menu menu){ // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); returntrue; }
@Override publicbooleanonOptionsItemSelected(MenuItem item){ // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if(id == R.id.action_settings){ returntrue; } returnsuper.onOptionsItemSelected(item); } }
4) values/styles.xml
<resources>
<!-- Base application theme using AppCompatv21 Library --> <stylename="AppBaseTheme"parent="Theme.AppCompat">
<!-- your app branding color for the app bar --> <itemname="colorPrimary">@color/md_blue_500_primary</item>
<!-- darker variant for the status bar and contextual app bars --> <itemname="colorPrimaryDark">@color/md_blue_700</item>
<!-- Change the Background color of the window in the activity --> <itemname="android:windowBackground">@color/md_white</item> <!-- theme UI controls like checkboxes and text fields --> <itemname="colorAccent">@color/md_red_200</item>
<!-- Chnaging the toolbar text color --> <!-- <item name="android:textColorPrimary">@color/md_red_500_primary</item> -->