小编Rea*_*hed的帖子

如何设置Listener切换导航抽屉?

actvity_main_drawer.xml

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

<group android:checkableBehavior="single">
    <item
        android:id="@+id/nav1"
        android:icon="@drawable/ic_lock_outline_black_24dp"
        android:title="test1" />
    <item
        android:id="@+id/nav2"
        android:icon="@drawable/ic_add_a_photo_black_24dp"
        android:title="test2" />
    <item
        android:id="@+id/nav3"
        android:icon="@drawable/ic_face_black_24dp"
        android:title="test3" />

</group>
Run Code Online (Sandbox Code Playgroud)

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include layout="@layout/content_main" />

<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"

    app:headerLayout="@layout/nav_header_main"
    app:menu="@menu/activity_main_drawer" />
Run Code Online (Sandbox Code Playgroud)

onoff_toggle.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="match_parent"
android:id="@+id/switch_layout"
android:layout_height="match_parent">

<android.support.v7.widget.SwitchCompat
    android:id="@+id/drawer_switch"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:checked="false"
    android:textOff="off"
    android:textOn="on"
    app:showText="true"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我在导航抽屉菜单项xml代码中的切换

如何设置Listener切换

xml android

1
推荐指数
1
解决办法
2217
查看次数

调试APK分发用于在Android L上构建并安装在Android K上时进行崩溃测试

所以我现在面对这个问题一段时间了.调试时我正在使用运行Android 5.1(L)的设备.当我完成后,我app-debug.apk从中获取/app/build/output/apk并通过Beta(由Fabric)将其转发给测试部门.

所以在测试人员方面,当安装在运行Android 4.4(K)的设备上时,应用程序在打开时会崩溃.这不是Fabric的问题,因为其他渠道如松弛,电子邮件等也会发生同样的事情.

如果我在运行Android K的模拟器上再次构建应用程序并发送apk,它将在测试设备上正常运行.是的,应用程序在运行Android 4.4的多个设备上崩溃了.

我在SO上找不到与此有关的内容,所以想想把它放好.这是Android Studio的已知问题还是我错过了什么?

我正在使用:

  • Android Studio V2.1.3
  • 闵.SDK版本15
  • 目标SDK版本23
  • 编译的SDK版本23
  • 构建工具版本24.0.2

如果这不是一个错误,这是否意味着我们必须在较低的Android版本上生成签名的apk,以便它可以在所有设备上运行?

有谁知道这个问题?

更新: Android K上崩溃的版本在Android L及更高版本上运行正常.

更新:我能够获得Logcat:

FATAL EXCEPTION: mainProcess: com.myapp.qa, PID: 3570 java.lang.RuntimeException: Unable to instantiate application com.android.tools.fd.runtime.BootstrapApplication: java.lang.ClassNotFoundException: Didn't find class "com.android.tools.fd.runtime.BootstrapApplication" on path: DexPathList[[zip file "/data/app/com.myapp.qa-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.myapp.qa-2, /vendor/lib, /system/lib]]
    at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4317)
    at android.app.ActivityThread.access$1500(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
Caused …
Run Code Online (Sandbox Code Playgroud)

java android android-gradle-plugin android-multidex android-studio-2.1

1
推荐指数
1
解决办法
1499
查看次数

Android SQL DATETIME CURRENT_TIMESTAMP

在我的 android 应用程序中,我有一个CURRENT_TIMESTAMP默认值的日期时间字段。问题是它插入的值与模拟器的时间不同。

  • 如何插入设备的当前日期和时间。

  • 我可以使用此列对表进行排序或删除 24 小时之前的记录吗?

这是我的代码:

public void onCreate(SQLiteDatabase db) {
   String query = "CREATE TABLE " + TABLE_BLOCKEDSMS + " (" +
            COLUMN_BLOCKEDSMS + " TEXT," +
            COLUMN_DATETIME + "DATETIME DEFAULT CURRENT_TIMESTAMP);";
    db.execSQL(query);
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

sqlite android android-sqlite

1
推荐指数
1
解决办法
4385
查看次数

Android:RecyclerView适配器longClickListener无法正常工作

我试图longClickListener在我的使用,Fragment但由于某种原因,它只是没有工作.如果我长按一下,就会收到活动onItemClickListener

这是我的代码

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
    private ArrayList<Info> Infos;
    private ClickListener clickListener;
    private MyLongClickListener myLongClickListener;

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        // each data item is just a string in this case
        public ImageView image;
        public/* Roboto */ TextView name;
        public/* Roboto */ TextView companyName;
        public/* Roboto */ TextView city;
        public/* Roboto */ TextView time;
        public/* …
Run Code Online (Sandbox Code Playgroud)

android onitemlongclicklistener android-recyclerview

0
推荐指数
1
解决办法
1332
查看次数

在Android Studio 2.1.3中构建错误

我正在使用android studio 2.1.3.我收到以下错误,尽管清理项目并重新重建,重新启动等...如何解决?

错误:任务执行失败:app:transformClassesWithJavaResourcesVerifierForDebug.

org.gradle.api.internal.changedetection.rules.DescriptiveChange无法强制转换为org.gradle.api.tasks.incremental.InputFileDetails可能已损坏(这有时会在网络连接超时后发生.)重新下载依赖项并同步项目(需要网络)

  • Gradle构建过程(守护程序)的状态可能已损坏.停止所有Gradle守护进程可以解决此问题.停止Gradle构建过程(需要重启)
  • 您的项目可能正在使用第三方插件,该插件与项目中的其他插件或项目请求的Gradle版本不兼容.
  • 在损坏的Gradle进程的情况下,您还可以尝试关闭IDE,然后终止所有Java进程.

    java android build emulation android-studio

    0
    推荐指数
    1
    解决办法
    1930
    查看次数

    片段回到最后,屏幕是白色的

    我有一个,它下面MainActivity有很多。Fragment

    我设置了返回机制transaction.addToBackStack(null);

    函数是这样的:

    public void switchFragment(Fragment fragment) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.mainFrame, fragment, null);
        transaction.addToBackStack(null);
        transaction.commit();
    }
    
    Run Code Online (Sandbox Code Playgroud)

    我的问题是当我单击后退按钮到底时,它FrameLayout是白色的 白屏

    我尝试添加

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {    
            if (mainFrame==null)
                return super.onKeyDown(keyCode, event);
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

    它不起作用。Fragment当我回拨到最后时如何避免出现白屏?任何帮助都会很棒!

    android

    0
    推荐指数
    1
    解决办法
    4042
    查看次数

    RecyclerViewAdapter 上的 SwitchCompat

    SwitchCompat在我的RecyclerView适配器中只使用一个。我需要点击项目的位置,RecyclerView当我使用TextView而不是SwitchCompat. 但是SwitchCompat没有响应,也没有返回位置。

    有人可以帮我吗?这是适配器文件。

    public class Setting_Recycler_Adapter extends RecyclerView.Adapter<Setting_Recycler_Adapter.ViewHolder> {
    
        private static final String TAG = "val" ;
        private Context mContext;
        private ArrayList<Channel_Model> channelsData;
        private Setting_Recycler_Adapter.ClickInterface click;
    
        public Setting_Recycler_Adapter(Context mContext, ArrayList<Channel_Model> data,Setting_Recycler_Adapter.ClickInterface clik) {
            this.mContext = mContext;
            this.channelsData = data;
            this.click = clik;
        }
    
        public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
            SwitchCompat mSwitchCompat;
    
            public ViewHolder(View itemView) {
                super(itemView);
    
                mSwitchCompat = (SwitchCompat) itemView.findViewById(R.id.setting_channel_switch);
                itemView.setOnClickListener(this);
            }
    
            @Override
            public void onClick(View …
    Run Code Online (Sandbox Code Playgroud)

    java android switchcompat

    0
    推荐指数
    1
    解决办法
    882
    查看次数