Какой класс импортировать для объявления переменной панели инструментов unsing androidx - PullRequest
0 голосов
/ 28 января 2020

Я пытаюсь построить панель инструментов. Когда я объявляю переменную панели инструментов в своем основном действии Java, я ожидаю ссылки на объект панели инструментов.

Я поставил ошибку в комментариях, думаю, это связано с androidx.appcompat.widget.Toolbar

---- вот моя основная деятельность xml file --- -

<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.appbar.AppBarLayout
    android:id="@+id/appbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/myToolbar"
        android:layout_height="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:background="@color/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

    </androidx.appcompat.widget.Toolbar>

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabIndicatorColor="@android:color/white"
        app:tabIndicatorHeight="2dp"
        app:tabMode="fixed"
        app:tabGravity="fill">

        <com.google.android.material.tabs.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="TAB1" />

        <com.google.android.material.tabs.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="TAB2" />

        <com.google.android.material.tabs.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="TAB3" />

        <com.google.android.material.tabs.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="TAB4" />

        <com.google.android.material.tabs.TabItem
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="TAB5" />
    </com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>

<androidx.viewpager.widget.ViewPager
    android:id="@+id/myViewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
    >

</androidx.viewpager.widget.ViewPager>

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorAccent"
        tools:context=".TvatActivity">

    </RelativeLayout>
</androidx.core.widget.NestedScrollView>

----- вот моя основная деятельность. java file

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.appcompat.widget.Toolbar
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import kotlinx.android.synthetic.main.activity_main.

class TvatActivity : AppCompatActivity() {
    private Toolbar toolbar; //Expecting Member declaration    
    private TableLayout tableLayout;  //Expecting Member declaration  
    private ViewPager viewpager; //Expecting Member declaration    

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        toolbar =(Toolbar) findViewById(R.id.myToolbar); //unresolved reference toolbar 
        tabLayout =(TabLayout) findViewById(R.id.tabs); //unresolved reference tabLayout
        viewpager =(ViewPager) findViewById(R.id.myViewPager);  //unresolved reference  viewpager

        setSupportActionBar(toolbar);
        setSupportViewPager(viewpager);
        tableLayout.setupWithViewPager(viewpager);
    }

---- QND ЗДЕСЬ МОЙ AAP gradle

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
    applicationId "com.youthimpact.tvap"
    minSdkVersion 16
    targetSdkVersion 29
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'com.google.firebase:firebase-auth:19.2.0'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
implementation 'com.google.firebase:firebase-storage:19.1.0'
implementation 'com.github.joielechong:countrycodepicker:2.4.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation 'junit:junit:4.12'

}

1 Ответ

0 голосов
/ 28 января 2020

Обычно в вашем xml макете с Androidx у вас есть

<com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbarlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

И вы устанавливаете тему NoActionBar в своем манифесте

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