使用没有 Theme.AppCompat 的 BottomNavigationView
Using BottomNavigationView with a no Theme.AppCompat
我需要使用主题
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
在一个 activity 中有一个
android.support.design.widget.BottomNavigationView
但每次我 运行 应用程序都会崩溃,因为 BottomNavigationView 需要 Theme.AppCompat。我该如何解决这个问题?
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tfdev.avventuratestuale">
<application
android:name=".Main.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen">
<activity android:name=".Main.Main.menu_principale"
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main.Main.scene_manager"
android:theme="@style/Theme.AppCompat"
></activity>
</application>
</manifest>
底部导航视图activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@layout/main_background">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="#FFFFFF"
app:itemTextColor="#FFFFFF"
app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>
底部导航Activity:
public class scene_manager extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
setContentView(R.layout.activity_scene_manager);
}
你不能。 BottomNavigationView 要求您使用 AppCompat 主题。
一种可能性是使用复制您需要的功能的第三方库(而不是使用 Google 视图)。
你当然可以将 BottomNavigationView
与 Holo 主题一起使用,尽管我不知道你为什么要这样做。
首先:不仅 BottomNavigationView,Activity
扩展的 AppCompatActivity
也需要 AppCompat 主题。按照您需要更改的内容进行操作:
1 - 从 Activity 扩展而不是 AppCompatActivity
public class scene_manager extends Activity {
// ....
}
注意: Class Java 中的名字不应该使用 snake_case 而是大驼峰式
2 - 直接将 AppCompat 主题应用到 BottomNavigationView
<RelativeLayout ... >
<android.support.design.widget.BottomNavigationView
...
android:theme="@style/Theme.AppCompat"
/>
</RelativeLayout>
这样它会起作用,但您将使用某些功能,例如 Toolbar
,因为您没有扩展 AppCompatActivity。
我已经修复添加
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
在所有 activity
我需要使用主题
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
在一个 activity 中有一个
android.support.design.widget.BottomNavigationView
但每次我 运行 应用程序都会崩溃,因为 BottomNavigationView 需要 Theme.AppCompat。我该如何解决这个问题?
我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tfdev.avventuratestuale">
<application
android:name=".Main.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen">
<activity android:name=".Main.Main.menu_principale"
android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main.Main.scene_manager"
android:theme="@style/Theme.AppCompat"
></activity>
</application>
</manifest>
底部导航视图activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@layout/main_background">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="#FFFFFF"
app:itemTextColor="#FFFFFF"
app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>
底部导航Activity:
public class scene_manager extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
setContentView(R.layout.activity_scene_manager);
}
你不能。 BottomNavigationView 要求您使用 AppCompat 主题。
一种可能性是使用复制您需要的功能的第三方库(而不是使用 Google 视图)。
你当然可以将 BottomNavigationView
与 Holo 主题一起使用,尽管我不知道你为什么要这样做。
首先:不仅 BottomNavigationView,Activity
扩展的 AppCompatActivity
也需要 AppCompat 主题。按照您需要更改的内容进行操作:
1 - 从 Activity 扩展而不是 AppCompatActivity
public class scene_manager extends Activity {
// ....
}
注意: Class Java 中的名字不应该使用 snake_case 而是大驼峰式
2 - 直接将 AppCompat 主题应用到 BottomNavigationView
<RelativeLayout ... >
<android.support.design.widget.BottomNavigationView
...
android:theme="@style/Theme.AppCompat"
/>
</RelativeLayout>
这样它会起作用,但您将使用某些功能,例如 Toolbar
,因为您没有扩展 AppCompatActivity。
我已经修复添加
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
在所有 activity