【发布时间】:2015-12-30 01:16:09
【问题描述】:
我在平板电脑 (API 22) 和手机 (API 23 和 22) 上设置 Snackbar 时遇到问题(从边缘到边缘)它工作正常(从边缘到边缘),即使在水平时也是如此。
结果如下 Snackbar:
FloatingActionButton(支持库)也不会移动(在手机上时会移动)。
我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/snackParent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/margin_fab"
android:layout_marginRight="@dimen/margin_fab"
app:pressedTranslationZ="12dp" />
</android.support.design.widget.CoordinatorLayout>
并在 MainActivity 中使用
private void showMessage(String msg) {
if(snackParent != null) {
snackbar = Snackbar.make(snackParent, msg, Snackbar.LENGTH_SHORT);
snackbar.setAction("OK", new View.OnClickListener() {
@Override
public void onClick(View v) {
snackbar.dismiss();
}
});
snackbar.show();
}
}
我只有其他资源文件,其尺寸(工厂边距)适用于平板电脑(w820dp),手机和平板电脑之间的样式文件夹相同。我也尝试过使 Android Studio 缓存无效。
我使用com.android.support:design:23.0.1targetSdkVersion=23 和compileSdkVersion=23, buildToolsVersion=23.0.1。
【问题讨论】:
-
我认为这是平板电脑上小吃店的默认行为。检查this out
-
是的,我刚刚在空项目上测试了较旧的支持库版本、targetSdkVersion 等,所有这些似乎都表明它是故意的。你可以发布你的回放作为答案吗?
-
这可能有点晚了,但以下对我有用:mSnackbar.getView().getLayoutParams().width = AppBarLayout.LayoutParams.MATCH_PARENT;
标签: android android-support-library android-snackbar floating-action-button