Created
June 6, 2018 05:39
-
-
Save kriishna/5cf8c8c1090df444ffdce1ea2609c74d to your computer and use it in GitHub Desktop.
BottomSheetDialogFragmentExample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.twitter.bottomdialogfragmentexample"> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity | |
android:name=".MainActivity" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme.NoActionBar" | |
android:windowSoftInputMode="adjustResize"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.twitter.bottomdialogfragmentexample; | |
import android.app.Dialog; | |
import android.os.Bundle; | |
import android.support.annotation.NonNull; | |
import android.support.design.widget.BottomSheetBehavior; | |
import android.support.design.widget.BottomSheetDialogFragment; | |
import android.support.design.widget.CoordinatorLayout; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.EditText; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
findViewById(R.id.launcher).setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
final MyBottomSheet quickShareSheet = new MyBottomSheet(); | |
quickShareSheet.show(getSupportFragmentManager(), "bottom_sheet"); | |
} | |
}); | |
} | |
public static class MyBottomSheet extends BottomSheetDialogFragment { | |
@NonNull | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
final Dialog dialog = super.onCreateDialog(savedInstanceState); | |
final View contentView = View.inflate(getContext(), R.layout.bottom_sheet, null); | |
dialog.setContentView(contentView); | |
final EditText editText = (EditText) contentView.findViewById(R.id.edit_text); | |
editText.setText("A\nB\nC\nD\nE\nF\nG"); | |
final View parentView = (View) contentView.getParent(); | |
final CoordinatorLayout.LayoutParams parentParams = | |
(CoordinatorLayout.LayoutParams) parentView.getLayoutParams(); | |
parentParams.setBehavior(new QuickShareSheetBottomBehavior()); | |
return dialog; | |
} | |
private static class QuickShareSheetBottomBehavior extends BottomSheetBehavior { | |
private QuickShareSheetBottomBehavior() { | |
setState(BottomSheetBehavior.STATE_EXPANDED); | |
setSkipCollapsed(true); | |
setHideable(false); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment