Tôi đang sử dụng Android BottomNavigationView
mới nhưng điều hướng dưới cùng MenuItem
chế độ xem tác vụ không hiển thị.Tại sao Android BottomNavigationView không hiển thị?
Sau khi gỡ lỗi, tôi thấy rằng mục menu không rỗng và khả năng hiển thị hiển thị.
Sau khi kiểm tra chiều cao và chiều rộng của chế độ xem gốc, nó sẽ đến 0 ngay cả sau khi mã hóa cứng các giá trị trong bố cục layout_width=50dp
và layout_height=50dp
của phần tử gốc.
Dưới đây là đáy menu điều hướng của tôi:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/nearby_fragment"
android:enabled="true"
android:icon="@drawable/homenearbyfragment"
android:title="@string/bottom_nearby"
app:showAsAction="always"/>
<item
android:id="@+id/route_fragment"
android:title="@string/bottom_homescreen"
android:enabled="true"
app:showAsAction="always"
android:icon="@drawable/home_mycommute" />
<item
android:id="@+id/newsfeed_activity"
android:title="@string/bottom_news"
android:enabled="true"
app:showAsAction="always"
android:icon="@drawable/newsfeed"
app:actionLayout="@layout/bagde_layout"/>
</menu>
bố trí hành động của tôi:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/actionButtonStyle"
android:layout_width="50dp"
android:layout_height="50dp"
android:clickable="true"
android:focusable="true"
android:gravity="center">
<ImageView
android:id="@+id/menu_badge_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/newsfeed" />
<TextView
android:id="@+id/menu_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|end"
android:layout_marginTop="4dp"
android:background="@drawable/circle_bg"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="8sp"
/>
Trong tôi Activity
Tôi cố gắng để thiết lập:
private void setCountOnNews(Menu menu) {
mReportMenu = menu.findItem(R.id.newsfeed_activity);
FrameLayout count = (FrameLayout) mReportMenu.getActionView();
count.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, NewsFeedActivity.class);
startActivity(intent);
MainApplication.getInstance().trackScreenView(getString(R.string.tracknewsfeedmenu));
}
});
TextView notifCount = (TextView) count.findViewById(R.id.menu_badge);
//if (Utils.getNewsfeedCountPreference(MainActivity.this) > 0)
notifCount.setText(String.valueOf(Utils.getNewsfeedCountPreference(MainActivity.this)));
notifCount.setText("asd;jfnapsdifnaspdifnasdpifnaspdfnapsdifnaspidfnapsidfnaspdiufif");
Log.d(TAG, "setCountOnNews:" + notifCount.getText().toString());
//else
// notifCount.setVisibility(View.GONE);
}
Bạn có thể đăng bài này dưới dạng dự án để github không? – azizbekian
bạn có thể đăng mã bố cục hoạt động xml không? –
@ user007 Bạn có thể đăng ảnh chụp màn hình trạng thái hiện tại không? – FAT