Не удается найти панель действий и панель инструментов класса символов [Android] - PullRequest
0 голосов
/ 25 апреля 2018

Я создаю приложение, которое использует Navigation Drawer. При запуске приложения у меня ошибка с именем cannot find symbol class actionbar and toolbar. Я не уверен, есть ли проблема с моим кодом Java или моим XML. Пожалуйста, помогите мне решить эту проблему.

MainPageActivity.java
public class MainPageActivity extends Activity {

//slider_menu için *******************************************************///////////
private DrawerLayout mDrawerLayout;

/////////////////************************
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mainpage);

    ///// ********************** toolbar -*************************
    mDrawerLayout = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.nav_view);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionbar = getSupportActionBar();
    actionbar.setDisplayHomeAsUpEnabled(true);
    actionbar.setHomeAsUpIndicator(R.drawable.ic_menu);

    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    // set item as selected to persist highlight
                    menuItem.setChecked(true);
                    // close drawer when item is tapped
                    mDrawerLayout.closeDrawers();

                    // Add code here to update the UI based on the item selected
                    // For example, swap UI fragments here

                    return true;
                }
            });

    /// **************************** Listen open and close slider menu button ******************************
    mDrawerLayout.addDrawerListener(
            new DrawerLayout.DrawerListener() {
                @Override
                public void onDrawerSlide(View drawerView, float slideOffset) {
                    // Respond when the drawer's position changes
                }

                @Override
                public void onDrawerOpened(View drawerView) {
                    // Respond when the drawer is opened
                }

                @Override
                public void onDrawerClosed(View drawerView) {
                    // Respond when the drawer is closed
                }

                @Override
                public void onDrawerStateChanged(int newState) {
                    // Respond when the drawer motion state changes
                }
            }
    );
    //**********************************************////////////////////
    ListView list;
    final String[] web = {
            getString(R.string.mainpage_acil),
            getString(R.string.mainpage_bildirim),
            getString(R.string.mainpage_isguveligi),

    };
    Integer[] imageId = {
            R.drawable.mainpage_acil_icon_p,
            R.drawable.mainpage_bildirim_icon_p,
            R.drawable.mainpage_isguvenligi_icon_p,
    };
    CustomListMainPage adapter = new
            CustomListMainPage(MainPageActivity.this, web, imageId);
    list = (ListView) findViewById(R.id.list);
    list.setAdapter(adapter);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            //Toast.makeText(MainPageActivity.this, "You Clicked at " + web[+position], Toast.LENGTH_SHORT).show();
            Log.v("Pozisyon", String.valueOf(position));
            Intent intentPos;
            ImageView imageView= (ImageView) view.findViewById(R.id.img);
            boolean flag=false;
            /// Renk değiştirme buraya tekrar bak***************
            switch (position) {
                case 0 :
                    //Toast.makeText(MainPageActivity.this, "You Clicked at " + web[+position], Toast.LENGTH_SHORT).show();
                    imageView.setImageResource(R.drawable.mainpage_acil_icon_p);
                    intentPos=new Intent(MainPageActivity.this,EmergencyActivity.class);
                    startActivity(intentPos);
                    break;

                case 1 :
                    imageView.setImageResource(R.drawable.mainpage_bildirim_icon_p);
                    intentPos=new Intent(MainPageActivity.this,NotificationPage.class);
                    startActivity(intentPos);                     break;

                case 2 :
                    imageView.setImageResource(R.drawable.mainpage_isguvenligi_icon_p);
                    intentPos=new Intent(MainPageActivity.this,JobSecurityActivity.class);
                    startActivity(intentPos);
                    break;

                default :
                    System.out.println("Hatali secim! 1, 2 ya da 3'e basiniz.");
                    break;
            }
        }
    });
}
//slider_menu buton ayarları için *******************************************************///////////
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            mDrawerLayout.openDrawer(GravityCompat.START);
            return true;
    }
    return super.onOptionsItemSelected(item);
}
//slider_menu buton ayarları için 
  *******************************************************///////////
 }
}

activity_mainpage.xml

     <?xml version="1.0" encoding="utf-8"?>
     <!-- Use DrawerLayout as root container for activity -->
     <android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/drawer_layout"
     android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
     app:menu="@menu/menu_main"
    app:headerLayout="@layout/nav_header"
    android:orientation="vertical"
    android:background="#000000">


       !-- Layout to contain contents of main body of screen (drawer will slide over this) -->
        <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <!-- Toolbar için ***********************************************-->
       <android.support.v7.widget.Toolbar
         android:id="@+id/toolbar"
        android:layout_width="match_parent"
         android:layout_height="?attr/actionBarSize"
          android:background="?attr/colorPrimary"
         android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
          <!-- Toolbar için *****************************************-->
          <!-- Container for contents of drawer - use NavigationView to make configuration easier -->
         <android.support.design.widget.NavigationView
         android:id="@+id/nav_view"
         android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
         android:fitsSystemWindows="true" />
       </FrameLayout>


        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       android:orientation="vertical"
        android:weightSum="60"
        android:alpha=".85"
         android:background="@drawable/mainpage_background"
       android:layout_marginBottom="10dp">
       <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="40"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="EMAS"
            android:textAlignment="center"
            android:textColor="@color/colorWhite"
            android:textSize="18sp"
            android:textStyle="bold" />
        </LinearLayout>

       <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:orientation="vertical"
        android:layout_weight="20">

        <include layout="@layout/mainpage_inner_part" />
      </LinearLayout>
      </LinearLayout>

      </android.support.v4.widget.DrawerLayout>

Я не уверен, есть ли проблема с моим кодом Java или моим XML. Пожалуйста, помогите мне решить эту проблему.

Ответы [ 2 ]

0 голосов
/ 25 апреля 2018

У меня недостаточно представителей, чтобы комментировать, поэтому пишите здесь.Android предоставляет шаблон для работы с навигационным ящиком.Вы можете использовать это.Выберите «Файл»> «Создать»> «Активность»> «Активность в окне навигации»

0 голосов
/ 25 апреля 2018

проверьте в своем файле манифеста Android в теге приложения в стиле, как показано ниже .. проверьте эту строку в файле манифеста Android ..

change this 

открытый класс MainPageActivity расширяет AppCompatActivity

        android:theme="@style/AppTheme"

затем примените стиль ниже.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
...