导航抽屉到QR扫描仪应用程序android studio

导航抽屉到QR扫描仪应用程序android studio,android,android-fragments,Android,Android Fragments,您好,我在创建应用程序时遇到问题。。我对编码比较陌生,我正在尝试将两个模板连接到一个应用程序,我有一个带有QR扫描仪的模板应用程序和另一个带有导航抽屉活动的模板应用程序。。我的问题是,我必须将导航抽屉添加到qr扫描器应用程序中,或者将qr扫描器添加到另一个应用程序中的碎片中 我的QR扫描仪应用程序如下所示 这是非常基本的,它有一个按钮,你按下它扫描二维码或条形码 现在我想在那里添加导航抽屉,但我真的不知道如何添加,因为我已经尝试过了,但它们总是导致多个错误 我的导航抽屉应用程序如下 主要活动

您好,我在创建应用程序时遇到问题。。我对编码比较陌生,我正在尝试将两个模板连接到一个应用程序,我有一个带有QR扫描仪的模板应用程序和另一个带有导航抽屉活动的模板应用程序。。我的问题是,我必须将导航抽屉添加到qr扫描器应用程序中,或者将qr扫描器添加到另一个应用程序中的碎片中

我的QR扫描仪应用程序如下所示

这是非常基本的,它有一个按钮,你按下它扫描二维码或条形码

现在我想在那里添加导航抽屉,但我真的不知道如何添加,因为我已经尝试过了,但它们总是导致多个错误

我的导航抽屉应用程序如下

主要活动

package net.simplifiedcoding.navigationdrawerexample;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;



public class MainActivity extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);



        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

        //add this line to display menu1 when the activity is loaded
        displaySelectedScreen(R.id.nav_menu1);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void displaySelectedScreen(int itemId) {

        //creating fragment object
        Fragment fragment = null;

        //initializing the fragment object which is selected
        switch (itemId) {
            case R.id.nav_menu1:
                fragment = new Menu1();
                break;
            case R.id.nav_menu2:
                fragment = new Menu2();
                break;
            case R.id.nav_menu3:
                fragment = new Menu3();
                break;
        }

        //replacing the fragment
        if (fragment != null) {
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.replace(R.id.content_frame, fragment);
            ft.commit();
        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
    }


    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {

        //calling the method displayselectedscreen and passing the id of selected menu
        displaySelectedScreen(item.getItemId());
        //make this method blank
        return true;
    }


}
我想要扫描仪的菜单1代码

package net.simplifiedcoding.navigationdrawerexample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Belal on 18/09/16.
 */


public class Menu1 extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //returning our layout file
        //change R.layout.yourlayoutfilename for each of your fragments
        return inflater.inflate(R.layout.fragment_menu_1, container, false);
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //you can set the title for your toolbar here for different fragments different titles
        getActivity().setTitle("Skanneri");
    }
}
我的活动\u main\u drawer.xml如下

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_menu1"
            android:icon="@android:drawable/ic_menu_camera"
            android:title="QR skanneri" />
        <item
            android:id="@+id/nav_menu2"
            android:icon="@android:drawable/ic_menu_mapmode"
            android:title="Kartta" />
        <item
            android:id="@+id/nav_menu3"
            android:icon="@android:drawable/ic_menu_help"
            android:title="Tietoa eri aloista" />

    </group>

</menu>
<?xml version="1.0" encoding="utf-8"?>



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="@style/TextAppearance.AppCompat.Button"
        android:text="Paina nappia skannataksesi QR-koodin"
        android:id="@+id/textView"
        android:layout_marginTop="27dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>
apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "net.simplifiedcoding.navigationdrawerexample"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.2.0'
    compile 'com.android.support:design:24.2.0'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:support-v13:23.0.1'
    compile 'com.google.zxing:core:3.2.0' //QRCode scanner
    compile 'com.facebook.rebound:rebound:0.3.8' //spring animation


}

我真的需要帮助,谢谢

似乎缺少了一些依赖项,因为您只包含了
core
包。尝试包括其他软件包,可能是
android内核
,因为您的错误似乎指向特定于android的软件包

  • 首先包括所需的依赖项
  • 清洁工程
  • 重建格拉德尔

  • 你得到了什么错误?@LaurIvan这些是我得到的错误,请添加依赖项。您可能遗漏了什么。@LaurIvan My build.gradle文件正在编辑中^^