Я дуже новий при кодуванні, і я намагався з'ясувати, як додати зображення на панель інструментів на Android. Чому це не працює?
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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"
tools:context="com.example.admin.prototypeapp.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
<android.support.v7.widget.Toolbar
style="@style/ToolBarStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
<ImageView
android:contentDescription="@string/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/white_logo_transparent"/>
</android.support.v7.widget.Toolbar>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
Чи можна вставити такий образ?
Він говорить мені, що /android.support.v7.widget.Toolbar має бути /android.support.design.widget.CoordinatorLayout
Новачок помилка? Чи є кращий спосіб зробити це?
Відповіді:
0 для відповіді № 1Тег XML для Toolbar
не закрито.Спробуйте це:
<android.support.v7.widget.Toolbar
style="@style/ToolBarStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary">
<ImageView
android:contentDescription="@string/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/white_logo_transparent"/>
</android.support.v7.widget.Toolbar>