Добавление границы ниже панели инструментов Android - PullRequest
0 голосов
/ 25 апреля 2018

Я пытаюсь добавить границу, которая бы выглядела так: https://imgur.com/a/r8rHGQl

Мой toolbar.xml:

<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_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:elevation="1dp"
app:theme="@style/AppTheme"
app:titleTextAppearance="@style/TitleText"
app:titleTextColor="@color/colorPrimaryText"

>
</android.support.v7.widget.Toolbar>

В моем коде Java я делаю: toolbar = findViewById(R.id.toolbar);setSupportActionBar(toolbar); и раздувание меню.

Если я попытаюсь вложить панель инструментов в относительное / линейное / ограниченное расположение и добавить вид внизу, я получаю «android.widget.LinearLayout не может быть приведен к Android.support.v7.widget.Toolbar "error

Также попытался <include макет с представлением внутри него, но затем линия появляется в середине моей панели инструментов, и мой заголовок исчезает.

Также включая мой menu.xml:

<?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:id="@+id/item1"
android:icon="@drawable/main_btn_info"
android:title="Item 1"
app:showAsAction="always"/>
</menu>

Ответы [ 2 ]

0 голосов
/ 28 апреля 2018
  1. Создание панели инструментов внутри линейного макета с видом

    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    
       <android.support.v7.widget.Toolbar    
       android:id="@+id/toolbar_main"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:background="@color/colorPrimary"
       android:elevation="1dp"
       app:theme="@style/AppTheme"
       app:titleTextAppearance="@style/TitleText"
       app:titleTextColor="@color/colorPrimaryText"/>
    
       <View 
       android:background="your border color"
       android:layout_width="match_parent"
       android:layout_height="2dp" />
    
    </LinearLayout>
    
  2. Включите это во все ваши макеты.

  3. Затем найдите панель инструментов в действии, используя идентификатор панели инструментов вместо имени XML

    toolbar = findViewById(R.id.toolbar_main); 
    setSupportActionBar(toolbar);
    
0 голосов
/ 28 апреля 2018

Сделал еще один макет с рамкой и включил его в каждое действие, я знаю, что это не лучший способ сделать это, но результат пока тот же.

...