我使用的是最新的Android BottomNavigationView
但底部導航MenuItem
動作視圖沒有顯示。爲什麼Android BottomNavigationView不顯示?
調試後,我發現該菜單項不爲空並且能見度可見。
在檢查根視圖的高度和寬度後,即使在對根元素的佈局layout_width=50dp
和layout_height=50dp
進行硬編碼之後,它也會變爲0。
這裏是我的底部導航菜單:
<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>
我的動作佈局:
<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"
/>
在我Activity
我想設置:
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);
}
你能張貼此作爲一個項目,GitHub上? – azizbekian
你可以發佈Activity xml佈局代碼嗎? –
@ user007能否請您發佈的當前狀態的屏幕截圖? – FAT