Android 棒棒糖版本的应用程序上未显示操作栏/工具栏
我目前正试图将我的应用程序转换为棒棒糖材质设计,但在操作栏/工具栏上遇到了一些问题。以我的方式实现所有功能,actionbar/工具栏不会显示在棒棒糖或kitkat设备上。也许有人可以看看我的主题、样式、活动(在这里我保存了一堆片段,是我唯一放置工具栏xml代码的地方)和mainactivity 谢谢 values/styles.xmlAndroid 棒棒糖版本的应用程序上未显示操作栏/工具栏,android,xml,android-actionbar,toolbar,android-5.0-lollipop,Android,Xml,Android Actionbar,Toolbar,Android 5.0 Lollipop,我目前正试图将我的应用程序转换为棒棒糖材质设计,但在操作栏/工具栏上遇到了一些问题。以我的方式实现所有功能,actionbar/工具栏不会显示在棒棒糖或kitkat设备上。也许有人可以看看我的主题、样式、活动(在这里我保存了一堆片段,是我唯一放置工具栏xml代码的地方)和mainactivity 谢谢 values/styles.xml <resources> <style name="Theme.MyTheme" parent="Theme.AppCompat.Light"
<resources>
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- Set AppCompat’s actionBarStyle -->
<item name="actionBarStyle">@menu/action_menu</item>
<!-- The rest of your attributes -->
</style>
</resources>
您的活动必须从使用新的AppCompat库时开始扩展。更改您的活动\u main.xml,如下所示
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<RelativeLayout
android:id="@+id/drawerView"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="start" >
<ListView
android:id="@+id/drawerList"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@drawable/nav_border"
android:divider="@null" />
</RelativeLayout>
<!--
<fragment
android:id="@+id/fragment1"
android:name="com.shamu11.madlibsportable.MadlibsSelect"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
-->
</android.support.v4.widget.DrawerLayout>
。它可能会帮助你。是的,如果发生这种情况,我已经浪费了一个多小时来修复它
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
这将自动同步并最终显示toogle图标
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
这对我很有用,希望能有所帮助。我已经这样做了,我还添加了一些代码来澄清。@shamu11您是否尝试过将父主题更改为“theme.AppCompat.Light.NoActionBar”你已经在布局中声明了工具栏,所以你应该没问题。实际上,我刚刚将true从true更改为false,现在我有了一个操作栏!你能推荐一种方法来修补这个动作栏并添加切换吗?谢谢在kitkat上,它似乎没有返回到actionbar,它只是显示一个小标题,上面写着我的应用程序的名称。因此,这似乎不是一个功能齐全的方式,但这是一个东西。你是说导航抽屉开关吗?工具栏的行为应该与旧的ActionBar完全相同,只需像操作栏一样添加切换。最糟糕的答案。其他人现在应该对这两个文件进行区分吗?
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<RelativeLayout
android:id="@+id/drawerView"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="start" >
<ListView
android:id="@+id/drawerList"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@drawable/nav_border"
android:divider="@null" />
</RelativeLayout>
<!--
<fragment
android:id="@+id/fragment1"
android:name="com.shamu11.madlibsportable.MadlibsSelect"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
-->
</android.support.v4.widget.DrawerLayout>
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}