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.
In lasp example of BottomSheet, I implement a OnClickListener of background to expand and collapse the bottom sheet. Without this, user cannot expand the bottom sheet if collapsed, because bottom sheet have height of 0 by default. If you want you can set the height of collapsed bottom sheet, by calling setPeekHeight() method.
This video show how:
MainActivity.java
package com.blogspot.android_er.androidbottomsheet;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
LinearLayout backgroundLayout;
View bottomSheet;
private BottomSheetBehavior bottomSheetBehavior;
TextView textPrompt;
TextView textSDK;
/*
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textSDK = (TextView)findViewById(R.id.textSDK);
textSDK.setText("Running SDK_INT: " + sdk_int);
textPrompt = (TextView)findViewById(R.id.prompt);
backgroundLayout = (LinearLayout)findViewById(R.id.backgroundlayout);
bottomSheet = findViewById(R.id.bottomsheet);
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
bottomSheetBehavior.setBottomSheetCallback(bottomSheetCallback);
bottomSheetBehavior.setPeekHeight(150);/*
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) {
}
};
}
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.
Master the highly acclaimed Material Design paradigm and give your apps and pages the look that everyone is talking about
Get a mix of key theoretical concepts combined with enough practical examples to put each theory into practice so you can create elegant material interfaces with Android Studio and Polymer
Written by Kyle Mew, successful author with over a decade of mobile and web development experience, this book has both the touch of a developer as well as an experienced writer
Book Description
Google's Material Design language has taken the web development and design worlds by storm. Now available on many more platforms than Android, Material Design uses color, light, and movements to not only generate beautiful interfaces, but to provide intuitive navigation for the user.
Learning Material Design will teach you the fundamental theories of Material Design using code samples to put these theories into practice.
Focusing primarily on Android Studio, you'll create mobile interfaces using the most widely used and powerful material components, such as sliding drawers and floating action buttons. Each section will introduce the relevant Java classes and APIs required to implement these components. With the rules regarding structure, layout, iconography, and typography covered, we then move into animation and transition, possibly Material Design's most powerful concept, allowing complex hierarchies to be displayed simply and stylishly.
With all the basic technologies and concepts mastered, the book concludes by showing you how these skills can be applied to other platforms, in particular web apps, using the powerful Polymer library.
What you will learn
Implement Material Design on both mobile and web platforms that work on older handsets and browsers
Design stylish layouts with the Material Theme
Create and manage cards, lists, and grids
Design and implement sliding drawers for seamless navigation
Coordinate components to work together
Animate widgets and create transitions and animation program flow
Use Polymer to bring Material Design to your web pages
About the Author Kyle Mew has been programming since the early eighties and has written for several technology websites. He has also written three radio plays and two other books on Android development.