Gok*_* NC 5 android material-design android-snackbar android-navigation-bar
我正在使用roughike的BottomBar 2.0:https : //github.com/roughike/BottomBar/
当我显示 SnackBar 时,它会显示在 BottomBar 本身上。
我希望它被绘制在 BottomBar 上方。
活动_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/here"
android:background="#fff">
<FrameLayout
android:id="@+id/contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomBar">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Three Buttons Bar"
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="@color/colorPrimary"
android:textSize="35sp" />
</FrameLayout>
<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs" />
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
主活动.java:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(int tabId) {
switch (tabId) {
case R.id.recent_item:
Snackbar.make(findViewById(R.id.main_activity), "Recent Item Selected", Snackbar.LENGTH_LONG).show();
break;
case R.id.favorite_item:
Snackbar.make(findViewById(R.id.main_activity), "Favorite Item Selected", Snackbar.LENGTH_LONG).show();
break;
case R.id.location_item:
Snackbar.make(findViewById(R.id.main_activity), "Location Item Selected", Snackbar.LENGTH_LONG).show();
break;
}
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
截图:
布局文件有什么问题吗??
我错过了什么??
我还检查了这一点:将小吃店移到底部栏上方,但没有帮助..
编辑:
我试过Abtin 说的:
Snackbar.make(bottomBar, "Location Item Selected", Snackbar.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)
和
<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs"
app:bb_behavior="underNavbar"/>
Run Code Online (Sandbox Code Playgroud)
现在变成了这样:
如您所见,当我设置时app:bb_behavior="underNavbar",BottomBar 下方有这个未使用的空间,这不是我想要的。
使用新的材料设计,Snackbars 有一个新的外观.. 你可以用下面这行在 BottomBar 上方显示Snackbar:
Snackbar snackbar = Snackbar.make(parentView, text, duration);
snackbar.setAnchorView(bottomBar);
Run Code Online (Sandbox Code Playgroud)
这将完成工作。
小智 6
您应该在 xml 中创建 CoordinatorLayout,从他的底部您希望将显示 SnackBar 并在 fun 时将 CoordinatorLayout 的 id 作为 View 的 id。使 SnackBar。
<android.support.design.widget.CoordinatorLayout
android:id="@+id/viewSnack"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp"/>
Run Code Online (Sandbox Code Playgroud)
内部活动:
Snackbar.make(findViewById(R.id.viewSnack), "Text of the SnackBar", Snackbar.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)
尝试更改传递到小吃店的视图。
Snackbar.make(findViewById(R.id.contentContainer), "Recent Item Selected", Snackbar.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9748 次 |
| 最近记录: |