gpt4 book ai didi

android - BottomNavigationView 未显示在我的 Activity 中

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:44:51 27 4
gpt4 key购买 nike

我正在使用这个 link 实现 BottomNavigationView我一步一步地实现了一切,但我的导航 View 没有显示在屏幕底部。

这就是我做的。

public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback {

Intent intent = null;
BottomNavigationView navigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

navigationView = (BottomNavigationView) findViewById(R.id.navigation);

navigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

int id = item.getItemId();
if(id == R.id.program){
intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
if(id == R.id.access){
try {
manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
overridePendingTransition(R.anim.push_up_in,
R.anim.push_up_out);
} else {
intent = new Intent(MainActivity.this, Access.class);
startActivity(intent);
finish();
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
if(id == R.id.informations){
intent = new Intent(MainActivity.this, Information.class);
startActivity(intent);
finish();
return true;
}
if(id == R.id.contact){
intent = new Intent(MainActivity.this, Contact.class);
startActivity(intent);
finish();
return true;
}
return false;
}
});
}
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu = navigationView.getMenu(); <---- // -->
getMenuInflater().inflate(R.menu.menu_main, menu);

return true;
}
}

和我的activity.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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite">

<android.support.design.widget.BottomNavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:design="http://schema.android.com/apk/res/android.support.design"
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
design:menu="@menu/menu_main" />
</android.support.design.widget.CoordinatorLayout>

而且我也更新了gradle版本到25,不然不行。

compileSdkVersion 25
buildToolsVersion "24.0.3"
targetSdkVersion 25

compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'

最佳答案

它不起作用的原因是 menu 位于错误的命名空间 (design)。请改用 app 命名空间。

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite">

<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_gravity="bottom"
app:menu="@menu/menu_main" />
</android.support.design.widget.CoordinatorLayout>

关于android - BottomNavigationView 未显示在我的 Activity 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40153888/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com