0
我試圖用工具欄替換ActionBar
,但工具欄不顯示。我不明白爲什麼我的頁面在沒有工具欄的情況下仍然是空白的,我錯過了什麼?工具欄不會顯示在Xamarin.Android
我的風格:
<style name="MyThemeActionBar" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
我toolbar.axml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toolbartitile"
android:text="Kodej"/>
</android.support.v7.widget.Toolbar>
我的活動:
[Activity(Label = "MainLoginActivity" , Theme = "@style/MyThemeActionBar")]
public class MainLoginActivity : AppCompatActivity
{
private ISharedPreferences sp;
private Android.Support.V7.Widget.Toolbar toolbar;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.MainLogin);
toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
sp = GetSharedPreferences(null, FileCreationMode.Private);
TextView tv = FindViewById<TextView>(Resource.Id.emailMain);
tv.Text = sp.GetString("email", null);
tv.Click += (object sender, EventArgs e) =>
{
Android.Support.V7.App.AlertDialog.Builder ad = new Android.Support.V7.App.AlertDialog.Builder(this);
ad.SetTitle("Logout");
ad.SetMessage("Are you sure you want to logout");
ad.SetPositiveButton("Yes", (senderAlert, args) =>
{
ISharedPreferencesEditor editor = sp.Edit();
editor.Remove("email");
editor.Apply();
StartActivity(typeof(MainActivity));
Finish();
});
ad.SetNegativeButton("Cancel", (senderAlert, args) => {});
Dialog dialog = ad.Create();
dialog.Show();
};
}
}
不幸的是我已經忘了這個職位,但說你呢是正確的錯誤是,我忘了把它放在主登錄,但謝謝你(你只是瞭解我,我可以使用,所以謝謝你) –
jgauthier
@jgauthier,那麼如果這個答案有幫助,你可以請[mar k這個答案](http://stackoverflow.com/help/someone-answers)? –