Как создать BottomNavigationView с помощью xamarin для Android API 19 - PullRequest
0 голосов
/ 13 сентября 2018

Я пытался показать вид снизу навигации на телефоне Android с API 19 с xamarin. Не работает Может кто-нибудь сказать мне, почему это не работает?

Мой код

    Resources/layout/Main.xaml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
                xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:gridSpec="1|8|#0093eeff|K:#ee8700ff:16,l:72,l:16,r|S:#83ee00ff:16,0,l:16,56,l:16,0,r">
  <!-- Header aligned to top -->
  <RelativeLayout
      android:id="@+id/header"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:background="@drawable/header_bg">
    <!-- TODO Fill Dynamic, Format, Position-->
    <TextView
        android:id="@+id/prodCount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="2dp"
        android:text="0 Artikel"
        style="@style/TotalTxt"
        android:layout_alignParentLeft="true" />

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        android:layout_alignParentBottom="true"
        app:menu="@menu/navigation" />
  </RelativeLayout>
</RelativeLayout>


Resources/menu/navigation.xaml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

  <item
      android:id="@+id/navigation_home"
      android:title="title_home" />

  <item
      android:id="@+id/navigation_dashboard"
      android:title="title_dashboard" />
</menu>

Проблема в том, что я получаю белый экран на смартфоне. Как я могу решить проблему?

Ответы [ 2 ]

0 голосов
/ 18 сентября 2018

Моя проблема в том, что я не могу установить зависимость "com.android.support:design:25.1.0", поскольку она не соответствует API 19. API устарел.

Вы можете изменить целевую версию Android для своего проекта для Android 7.0 (API 24) или выше, затем вы можете скачать этот дизайн поддержки Android.enter image description here

Обратите внимание: сохранить целевую версию в соответствии с скомпилированной версией enter image description here

enter image description here

Я делаю один пример создания BottomNavigationView с xamarin для Android.

1. Загрузите и установите Xamarin.Android.Support.Design в пакете управления NuGet…

enter image description here 2.создать новую папку menu в каталоге Resources и добавить новый файл .xml, создав navigation_main.xml в Resources/menu/

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">

  <item
android:orderInCategory="0"
android:id="@+id/menu_genres"
android:enabled="true"
android:title="Genres"
android:icon="@drawable/abc_ic_ab_back_material"
app:showAsAction="always" />

  <item
android:orderInCategory="1"
android:id="@+id/menu_titles"
android:enabled="true"
android:title="Titles"
android:icon="@drawable/abc_ic_ab_back_material"
app:showAsAction="always" />

  <item
android:orderInCategory="2"
android:id="@+id/menu_stream"
android:enabled="true"
android:title="Stream"
android:icon="@drawable/abc_ic_ab_back_material"
app:showAsAction="always" />

  <item
android:orderInCategory="3"
android:id="@+id/menu_showtimes"
android:enabled="true"
android:title="Showtimes"
android:icon="@drawable/abc_ic_ab_back_material"
app:showAsAction="always" />

</menu>

3.Нижняя навигация работает путем замены фрагментов, когда выбран один из элементов.Это означает, что в нашем Android XML также должен быть FrameLayout для обмена фрагментами, которые будут отображаться.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

 <FrameLayout
     android:id="@+id/fragment_content"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_above="@+id/bottom_navigation" />

 <android.support.design.widget.BottomNavigationView
     android:id="@+id/bottom_navigation"
     android:layout_width="match_parent"
     android:layout_height="56dp"
     android:layout_gravity="start"
     android:layout_alignParentBottom="true"
     android:background="@android:color/white"
     app:menu="@menu/navigation_main" />

Для получения дополнительной информации, пожалуйста, посмотрите следующую статью: https://blog.xamarin.com/exploring-androids-bottom-navigation-view/

0 голосов
/ 13 сентября 2018

Пожалуйста, посмотрите на эту статью:

https://blog.iamsuleiman.com/using-bottom-navigation-view-android-design-support-library/

Это решение для Android, а не для Xamarin / C #, но, возможно, может помочь вам.

Кроме того, я провел несколько тестов с использованием Xamarin.Forms и новых Bottom Navigation / Bottom Tabs на Android и отлично работает с API 19, только что возникла проблема с рисованными векторами, и я решил w /: AppCompatDelegate.CompatVectorFromResourcesEnabled = true;

Надеюсь, это поможет вам.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...