小编Ksh*_*wal的帖子

如何在SD卡上自动创建目录

我正在尝试将我的文件保存到以下位置,
FileOutputStream fos = new FileOutputStream("/sdcard/Wallpaper/"+fileName); 但是我得到了异常java.io.FileNotFoundException
但是,当我把路径保存"/sdcard/"起来的时候.

现在我假设我无法以这种方式自动创建目录.

有人可以建议如何创建directory and sub-directory使用代码吗?

android android-file

185
推荐指数
12
解决办法
26万
查看次数

webview在右侧显示白色酒吧

我给我的布局中嵌入的webview客户端提供以下方法调用
wv.loadData("<html><body bgcolor=\"Black\"></body></html>","text/html", "utf-8");

当我在设备上运行它时,它在右侧显示一个白色垂直条.我通过使用固定白色的东西,webview.setBackgroundColor(Color.BLACK);但我想完全删除它

以下是我的布局xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
    <WebView android:id="@+id/wv1"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            />

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

有什么建议??

android

56
推荐指数
2
解决办法
2万
查看次数

如何在按钮视图上启用触觉反馈

我想在我的应用程序按钮中添加触觉反馈,并以编程方式控制它们以显示按钮状态(启用和禁用).默认触觉反馈设置器仅适用于长按.如何使其适用于简单的按钮点击.

有没有办法对触摸移动等事件进行触觉反馈?

android vibration

35
推荐指数
4
解决办法
5万
查看次数

在Ionic 2中集成JavaScript Web插件

我试图将Applozic聊天平台集成到我的Ionic 2项目中,我希望将其导出到Web,Android和iOS.使用示例作为基础并为Javascript集成过程创建applozic.d.ts和applozichv.js.

applozic.d.ts

interface AppLozicStatic {
    initPlugin(): any;
}

declare var AppLozic : AppLozicStatic;
export = AppLozic;
Run Code Online (Sandbox Code Playgroud)

applozichv.js

(function () {
    var root = this;

    var AppLozic = function (obj) {
        if (obj instanceof AppLozic) return obj;
        if (!(this instanceof AppLozic)) return new AppLozic(obj);
        // this.EXIFwrapped = obj;
    };

    if (typeof exports !== 'undefined') {
        if (typeof module !== 'undefined' && module.exports) {
            exports = module.exports = AppLozic;
        }
        exports.AppLozic = AppLozic;
    } else …
Run Code Online (Sandbox Code Playgroud)

javascript jquery applozic ionic2

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

"即使在使用命名空间http://schemas.android.com/apk/res-auto后,也找不到属性'错误的资源标识符

林移植现有应用摇篮构建系统,并得到了以下错误,而从做一个构建命令行 error: No resource identifier found for attribute 'ignore_vertical_scroll' in package 'com.example.dummyapp'

现在'ignore_vertical_scroll'是在布局中attrs.xml使用它定义的自定义属性abc:ignore_vertical_scroll="true"xmlns:abc="http://schemas.android.com/apk/res-auto"

我到目前为止所读到的是,这个URI是在ADT 17.0中添加的,以缓解自定义组件中的包名称问题.不确定这是如何在gradle中翻译的.

android gradle android-studio build.gradle

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

带有中心按钮弧形或驼峰的底部导航

希望使用一个主要的中心操作按钮修改底部导航栏,该按钮改变导航栏本身的形状,或者像这样的弧形 在此处输入图片说明

或者底部导航中的一个驼峰包围着它周围的中心按钮。

如果我必须延长,我很好,BottomNavigationView但我不知道从哪里开始。

我发现了这个类似的问题,但这不是我想要解决的确切问题。

mobile android material-design bottomnavigationview

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

Android 3手指触摸检测

我能够使用以下代码成功记录屏幕上触摸的两个手指的坐标:

case MotionEvent.ACTION_MOVE:
Log.d("TOUCH", "test ACTION MOVE" + event.getPointerCount());
Log.d("TOUCH", "test ACTION MOVE ID" + event.getPointerId(0) + " "+event.getPointerId(1));
if(event.getPointerCount()==3)
{

x0 = (int) event.getX(event.getPointerId(0));
y0 = (int) event.getY(event.getPointerId(0));
x1 = (int) event.getX(event.getPointerId(1));
y1 = (int) event.getY(event.getPointerId(1));
x2 = (int) event.getX(event.getPointerId(2));
y2 = (int) event.getY(event.getPointerId(2));

Log.d("TOUCH", "test ACTION DOWN " + " values = " + x0 + " " + y0 + " "
+ x1 + " " + y1+ " "+x2 + " " + y2);
} …
Run Code Online (Sandbox Code Playgroud)

android multi-touch

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

android应用程序离线模式,本地sqlite数据库与远程数据库同步

我有一个postgreSql数据库,由一个Android应用程序通过Web服务操作.我想知道为我的应用程序制作离线模式的最佳方法是什么.

我的第一个想法是在设备无法访问Web时使用sqlite本地数据库

我想知道是否有现有的工具,一旦设备可以访问web ,就可以使现有的postgres数据库更容易同步

sqlite postgresql android synchronization offline-mode

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

Android上的Volley + OkHttp在状态200响应时出错

当我只用Volley提出请求时,一切顺利,我的StringRequest转到onResponse.

但当我切换到Volley + Okhttp组合时,我的请求通过,我收到与以前相同的响应,但后来我收到以下错误消息:

E/Volley? [122319] BasicNetwork.performRequest: Unexpected response code 200 for <my request url> java.io.IOException: closed com.android.volley.NetworkError: java.io.IOException: closed at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:182) at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114) Caused by: java.io.IOException: closed at okio.RealBufferedSource$1.read(RealBufferedSource.java:345) at java.io.InputStream.read(InputStream.java:162) at com.android.volley.toolbox.BasicNetwork.entityToBytes(BasicNetwork.java:254) at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:130)             at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:114)

我使用这个https://gist.github.com/bryanstern/4e8f1cb5a8e14c202750为我的OkHttpStack for Volley.

android android-volley okhttp

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

静态选项菜单

我想为我的所有活动屏幕创建一个静态选项菜单.我不想onCreateOptionsMenu()在每个活动中覆盖.

由于Menu类是具有大量方法的接口,因此很难创建实现类的静态对象.

还有其他方法吗?

user-interface android

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

Android中自动对焦后的视频录制问题

我正在尝试构建一个应用程序,尝试在开始视频录制之前自动对焦相机.直接使用MediaRecorder不会自动对焦相机.为此我使用Camera和使用回调我可以自动对焦它.但是提供这个实例给MediaRecorder了我很多问题.以下是用于录制的代码

public boolean startRecording()
{
    try
    {
        mCamera.unlock();

        mediaRecorder = new MediaRecorder();
        mediaRecorder.setCamera(mCamera);

        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

        CamcorderProfile profile = CamcorderProfile
                .get(CamcorderProfile.QUALITY_LOW);
        mediaRecorder.setProfile(profile);

        mediaRecorder.setMaxDuration(maxDurationInMs);

        File file = new File(outputFile);
        if (file.exists())
            file.delete();
        file = new File(outputFile);

        try
        {
            file.createNewFile();
        }
        catch (IOException e1)
        {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            Log.e("Deepak", "*** first catch ***");
        }


        mediaRecorder.setOutputFile(outputFile);
        mediaRecorder.setPreviewDisplay(mHolder.getSurface());

        mediaRecorder.setMaxFileSize(maxFileSizeInBytes);

        mediaRecorder.prepare();
        mediaRecorder.start();

        return true;
    }
    catch (IllegalStateException e)
    {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return false;
    }
    catch (IOException …
Run Code Online (Sandbox Code Playgroud)

android android-2.2-froyo android-camera

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

从另一个片段调用一个片段

我解释的事情非常糟糕,我会努力做到最好:)

我试图使用Tabhost并在每个选项卡中显示列表片段.

[tabview中的ListFragments]:在此输入图像描述

这是它的外观.

单击列表元素后,将调用另一个片段以显示详细信息,如下所示.[在列表元素上单击]:在此输入图像描述 有两个问题.

  1. DetailsFragment不是全屏.即能够看到列表(你可以在上图中看到)
  2. 当我回到标签视图并单击列表时,它会显示: "java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread.[in ListView(16908298, class android.widget.ListView) with Adapter(class android.widget.SimpleAdapter)] "TabView xml:

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                android:orientation="horizontal" />
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0" />
    
            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp" …
    Run Code Online (Sandbox Code Playgroud)

android list tabview android-fragments

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

在RecyclerView中为棒棒糖之前的可绘制着色

我正在尝试在我的RecyclerView中使用以下代码使用可绘制着色

Drawable likeDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_thumb_up);
Drawable likeWrappedDrawable = DrawableCompat.wrap(likeDrawable);
DrawableCompat.setTint(likeWrappedDrawable,ContextCompat.getColor(getActivity(), android.R.color.white));
holder.ivLike.setImageDrawable(likeWrappedDrawable);
Run Code Online (Sandbox Code Playgroud)

现在,所有这些工作都在onBindViewHolderRecyclerView Adapter的中完成。

我会根据该列表项的状态在三种颜色之间更改此色调。对于Lolipop及更高版本,这一切正常,但在此版本以下,列表项目的颜色是无法预测的。有时它显示正确的颜色,但刷新列表时有时会更改为其他颜色。

Anything im doing wrong here or the tinting thing on pre-lollipop is still unusable in this particular case?

Update Including the code from my onBindViewHolder

@Override
        public void onBindViewHolder(ViewHolder holder, int position) {
...

            Drawable likeDrawable =
                    ContextCompat.getDrawable(getActivity(), R.drawable.ic_thumb_up);


            Drawable likeWrappedDrawable = DrawableCompat.wrap(likeDrawable);


                holder.tvLikeCount.setTextColor(ResUtil.getColor(R.color.light_font,
                        getActivity()));

                DrawableCompat.setTint(likeWrappedDrawable,
                        ContextCompat.getColor(getActivity(), android.R.color.white));

                if (tweetModel.isFavorited()) {
                DrawableCompat.setTint(likeWrappedDrawable,
                        ContextCompat.getColor(getActivity(), android.R.color.holo_blue_light));
            }



            holder.ivLike.setImageDrawable(likeWrappedDrawable);

        }
Run Code Online (Sandbox Code Playgroud)

android android-drawable android-recyclerview

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