Android 底页不工作。下面是我的代码,我想创建底部表演示,但它不工作并且底部表没有显示。
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
private BottomSheetBehavior mBottomSheetBehavior;
private Button button1;
private View bottomSheet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getId();
setListner();
mBottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);
}
private void getId() {
try {
button1 = (Button)findViewById(R.id.button1);
bottomSheet = findViewById(R.id.bottom_sheet);
} catch (Exception e) {
e.printStackTrace();
}
}
private void setListner() {
try {
button1.setOnClickListener(this);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onClick(View v)
{
try {
switch (v.getId())
{
case R.id.button1:
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
Log.e("Buttom clicked",">>");
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
这是我的 xml 文件。
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1"
android:padding="16dp"
android:layout_margin="8dp"
android:textColor="@android:color/white"
android:background="@android:color/holo_green_dark"/>
</LinearLayout>
</ScrollView>
<android.support.v4.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="350dp"
android:clipToPadding="true"
android:background="@android:color/holo_orange_light"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher"
android:padding="16dp"
android:textSize="16sp"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
实际上,我想Android Support Library 23.2
使用以上代码来实现底部工作表,而不使用任何其他库,但它不起作用。谢谢和提前。