日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

c# – 在Android 7.0上不會調(diào)用OnCreateOptionsMenu

 印度阿三17 2019-07-10

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

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

這個方法在Android 7.0上有什么問題,或者我的代碼有問題嗎?

我的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./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./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./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>
來源:https://www./content-1-316001.html

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多