免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
c# – 在Android 7.0上不會(huì)調(diào)用OnCreateOptionsMenu

正如在上面提到的標(biāo)題中那樣,在我將系統(tǒng)更新到Android 7.0之后,不會(huì)調(diào)用OnCreateOptionsMenu方法.

在更新之前,我使用的是Android 6.0,它沒(méi)有任何問(wèn)題.
如果我在6.0的另一部手機(jī)上測(cè)試它仍然有效(相同的代碼).

這個(gè)方法在Android 7.0上有什么問(wèn)題,或者我的代碼有問(wèn)題嗎?

我的MainActivity.cs的一部分,我設(shè)置了toolbar

[Activity(Label = "App", Icon = "@drawable/icon", MainLauncher = true, Theme = "@style/Theme.AppCompat.Light.NoActionBar",ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]public class MainActivity : AppCompatActivity{    protected override void OnCreate(Bundle bundle)    {         base.OnCreate(bundle);         SetContentView(Resource.Layout.Main);         var toolbar = FindViewById<Android.Widget.Toolbar>(Resource.Id.toolbar);         toolbar.SetTitleTextColor(Color.White);         SetActionBar(toolbar);    }    public override bool OnCreateOptionsMenu(IMenu menu)    {        MenuInflater.Inflate(Resource.Menu.top_menu_start, menu);        return base.OnCreateOptionsMenu(menu);    }}

Main.axml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <Toolbar        android:id="@ id/toolbar"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="#1D1D1D"        android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar" /></RelativeLayout>

top_menu_start

<menu xmlns:android="http://schemas.android.com/apk/res/android">  <item       android:id="@ id/start_listview"       android:icon="@drawable/icon_posts_list"       android:showAsAction="ifRoom"       android:title="startListview" />  <item       android:id="@ id/start_pager"       android:icon="@drawable/icon_posts_kacheln"       android:showAsAction="ifRoom"       android:title="startPager" />  <item       android:id="@ id/doSomething"       android:icon="@drawable/icon"       android:showAsAction="ifRoom"       android:title="doSomething" /></menu>

解決方法:

由于您使用的是AppCompatActivity,因此您應(yīng)該使用Android.Support.V7.Widget.Toolbar而不是Android.Widget.Toobar并調(diào)用SetSupportActionBar而不是SetActionBar.現(xiàn)在將調(diào)用您的OnCreateOptionsMenu.

OnCreate覆蓋:

base.OnCreate(savedInstanceState);SetContentView(Resource.Layout.Main);var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);toolbar.SetTitleTextColor(Color.White);SetSupportActionBar(toolbar);

Main.axml更新:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent">    <android.support.v7.widget.Toolbar        android:id="@ id/toolbar"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="#1D1D1D"        android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar">    </android.support.v7.widget.Toolbar>
來(lái)源:https://www.icode9.com/content-1-316001.html
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
NoActionBar主題下如何添加OptionsMenu
求教android實(shí)現(xiàn)短信圖標(biāo)右上角添加數(shù)字的問(wèn)題。。跪求大神。。。
Android之解決androidx.appcompat.widget.Toolbar去掉左邊距
Android:Theme.Material和Theme.AppCompat
讓你的 APP換上Material Design
開(kāi)發(fā)App抽屜功能,徹底掌握了嗎?
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服