Java android.support.v7.widget.Toolbar无法正常工作

Java android.support.v7.widget.Toolbar无法正常工作,java,android,toolbar,Java,Android,Toolbar,可以这样说,工具栏在“设计”部分中未正确显示。它的大小是不变的。为其设置的属性集不会显示在“设计”字段中。属性,如背景、颜色和 xml代码: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schem

可以这样说,工具栏在“设计”部分中未正确显示。它的大小是不变的。为其设置的属性集不会显示在“设计”字段中。属性,如背景、颜色和

xml代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar2"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        android:theme="?attr/actionBarTheme"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="49dp" />

</android.support.constraint.ConstraintLayout>

style.xml
添加此

MainActivity.xml

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/green">

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

我这样做是为了我的项目和工作:
首先,必须在res中的样式文件中添加此样式

<style name="ToolBarTheme" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
    </style>

将光标移到(!)符号的顶部,这样您就可以看到错误。我可以看到您的xml文件的文本吗?@fatemeh fallahi arezoudar:添加的xml文件删除这些行
tools:layout\u editor\u absoluteX=“8dp”tools:layout\u editor\u absoluteY=“49dp”2009/码码码><<style name="ToolBarTheme" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textColorSecondary">@android:color/white</item>
    </style>
<android.support.v7.widget.Toolbar
    android:layoutDirection="rtl"
    android:elevation="8dp"
    android:id="@+id/ToolBarMain"
    android:background="?attr/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:theme="@style/ToolBarTheme"
    tools:ignore="UnusedAttribute">
</android.support.v7.widget.Toolbar>
apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.yasin.taksmssender"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:27.1.1'

}