Ken

Talk is cheap. Show me the code


  • 首页

  • 标签

  • 分类

  • 归档

  • 关于

  • Sitemap

  • 搜索

AndroidStudio导项目时的一些问题

发表于 2016-01-11 | 分类于 Android |

这里陆陆续续的收录一些关于AS的问题。
今天在GitHub上面发现一个好的项目,导入到AS里面竟发现不能运行,报的错误也是千奇百怪,

1
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/NOTICE

有这么一排错误,Google了半天,要这样做,在你的gradle中加入

1
2
3
4
5
6
7
8
9
10
11
12
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}

还有一个问题如果你想在API23中使用AndroidHttpClient,必须要这么做。在你的build.gradle中加入

1
2
3
android {
useLibrary 'org.apache.http.legacy'
}

因为Android 6.0已经废弃了支持Apache HTTP client. 官方不建议使用了,如果迫不得已使用,加上那个就好了。

版权声明:



除非注明,本博文章均为原创,转载请以链接形式标明本文地址。

阅读全文 »

用MaterDesign设计一个详情页面

发表于 2016-01-09 | 分类于 Android |
使用Hexo在GitHub上搭建个人博客
阅读全文 »

用TextInputLayout打造友好的Login页面

发表于 2016-01-07 | 分类于 Android |

看下面的gif是不是感觉比一般的登陆页面要人性化的多啊,App除了数据是活的,界面在我们的手中也要动起来,今天一起来实现一个这样的友好的Login界面。

上面的两个实际上就是我们平时用的EditText,不一样的是我们给EditText又穿了一件花衣裳,他才会变成这样
android.support.design.widget.TextInputLayout
写到这里你有可能知道了,想用这个你要在你的gradle中引入
compile 'com.android.support:design:23.1.1'。
就好了
来看布局代码

1
2
3
4
5
6
7
8
9
10
11
12
<android.support.design.widget.TextInputLayout
android:id="@+id/emailView"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/emailEt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="UserName"
android:inputType="textEmailAddress" />
</android.support.design.widget.TextInputLayout>

就这么简单,文章都在java代码,我们来实现它。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
TextInputLayout tl_email = (TextInputLayout) findViewById(R.id.emailView);
tl_username.setHint("请输入正确的邮箱地址");
//点击登录按钮
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() &#123;
@Override
public void onClick(View v) &#123;
String email = tl_username.getEditText().getText().toString().trim();
//正则匹配邮箱地址
if (!validateEmail(email)) &#123;
//友好的错误提示
tl_username.setError("The emailAddress error");
&#125;else &#123;
//将错误提示关掉
tl_username.setErrorEnabled(false);
//执行登录操作
doLogin();
&#125;
&#125;
&#125;);

public void doLogin()&#123;
//下方提示登录成功,第一个参数为父布局就好
Snackbar.make(parentView, "Login Sucess",
Snackbar.LENGTH_SHORT).setAction("login Sucess", null).show();
&#125;

你可以试一试

版权声明:



除非注明,本博文章均为原创,转载请以链接形式标明本文地址。

阅读全文 »

Android猿猿们的福利

发表于 2015-12-26 | 分类于 Android |

Google小游戏

可能大多数的人都用的惯Google,但是当没有网络的时候,Google也给我们调了一个皮,当你不经意间按下Space键,奇迹的事情发生了,嘿嘿,无聊吧!

年末了,下面分享一下今年我收藏的书吧。

< stream />
< figure https://img3.doubanio.com/lpic/s27243455.jpg Java编程思想 />< endstream />
有一定的java基础,学好android事半功倍,java不好的android程序员不是好工程师。所以这本java圣经推荐大家一看。

< stream />
< figure https://img3.doubanio.com/lpic/s28351121.jpg 第一行代码 />< endstream />
郭霖大大的这本《第一行代码》,乃android入门必备,android圣经级的,时不时的翻一翻,会有意想不到的收获。
< stream />
< figure https://img3.doubanio.com/lpic/s28283342.jpg Android群英传 />< endstream />
如果你想在android界自定义View有一席之地,“医生”的这本《群英传》非你莫属。

< stream />
< figure https://img3.doubanio.com/lpic/s28283341.jpg Android开发艺术探索 />< endstream />
如果你不想在android界平庸,那么“主席”的这本的《艺术探索》,是祝你走向人生的巅峰,赢取白富美的必经之路。

< stream />
< figure https://img3.doubanio.com/lpic/s28320163.jpg Android 源码设计模式解析与实战 />< endstream />
如果你在android界有啥深入的疑惑,那么SM哥的这本《源码设计模式》你有必要看看了。

< stream />
< figure https://img3.doubanio.com/lpic/s28333166.jpg App研发录:架构设计、Crash分析和竞品技术分析 />< endstream />
一些平时看起来不起眼的小地方,却被作者写的如此“惟妙惟肖”。

< stream />
< figure https://img3.doubanio.com/lpic/s4157180.jpg 重构 />< endstream />
如果你对你自己或者别人的代码有啥意见,但是又不敢轻易的去乱动,那么这本《重构》,你要时刻拜读了。

阅读全文 »

AndroidStudio快速生成常用模板

发表于 2015-12-19 | 分类于 AndroidStudio |

从刚开始用AS的时候,还有一丝的Eclipse的味道,但是有一些在Ec上面很方便的东西,在AS上面却一无所措了,比如之前在Ec上面的syso输出的便是System.out.println();然而在AS上面他却没有这么干,而是用sout来输出,今天就带着这个疑惑,这个东西我们从那可以找到并修改成我们熟知的那?

当你知道了就很简单了,打开AS,打开设置页面,找到Editor,下面的Live Templates

你想知道的全在这里面,图中我选中的就是我们经常用到的Toast,我把他改成了tst,我们只要在代码中输入tst,即可出来下面的Template text中生成的一句代码,还有我们经常用的findViewById等等,你可以一个个点开,看看他的描述,然后加上自己的熟悉的快捷短语即可。

版权声明:



除非注明,本博文章均为原创,转载请以链接形式标明本文地址。

阅读全文 »

判断App是否在模拟器上运行

发表于 2015-12-16 | 分类于 Android |

我们之前看友盟的统计,发现有一些bug,都是在模拟器类型报的错,我们干脆就不让在模拟器安装了,下面我们来看一下。

首先我们来看一下Runtime这个类,他是一个与JVM运行时环境有关的类,这个类是Singleton的。

1
Allows Java applications to interface with the environment in which they are running. Applications can not create an instance of this class, but they can get a singleton instance by invoking getRuntime().

上面是在developer上面摘的Runtime.

这里面有这么几个重要方法,exec(),gc(),getRuntime(),maxMemory(),exit()等等,我们今天主要看exec方法,exec有六个重载。也就是我们今天要看的。

如果想与调用的程序进行交互,那么就要使用该方法的返回对象Process了,通过Process的getInputStream(),getOutputStream()和getErrorStream()方法可以得到输入输出流,然后通过InputStream可以得到程序对控制台的输出信息,通过OutputStream可以给程序输入指令,这样就达到了程序的交换功能。

先来上代码,光说理论就没意思了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* 判断是否在模拟器上运行
*
* @return
*/
public static boolean isRunningInEmualtor() &#123;
boolean quemuKernel = false;
Process process = null;
DataOutputStream os = null;
BufferedReader in = null;
try &#123;
process = Runtime.getRuntime().exec(".\\a.exe");
os = new DataOutputStream(process.getOutputStream());
in = new BufferedReader(new InputStreamReader(
process.getInputStream(), "GBK"));
os.writeBytes("exit\n");
os.flush();
process.waitFor();
quemuKernel = (Integer.parseInt(in.readLine()) == 1);
&#125; catch (Exception e) &#123;
quemuKernel = false;
&#125; finally &#123;
if (process != null) &#123;
process.destroy();
process = null;
&#125;
if (in != null) &#123;
try &#123;
in.close();
&#125; catch (IOException e) &#123;
e.printStackTrace();
&#125;
in = null;
&#125;
if (os != null) &#123;
try &#123;
os.close();
os = null;
&#125; catch (Exception e) &#123;
e.printStackTrace();
&#125;
&#125;
&#125;
return quemuKernel;
&#125;

第一行的“.\a.exe”是要执行的程序名,Runtime.getRuntime()返回当前应用程序的Runtime对象,该对象的exec()方法指示Java虚拟机创建一个子进程执行指定的可执行程序,并返回与该子进程对应的Process对象实例。通过Process可以控制该子进程的执行或获取该子进程的信息。

上面这个代码直接拿着用就好,然后把执行的程序名换成自己的就好。

1
2
3
4
5
6
if (Utils.isRunningInEmualtor()) &#123;
Toast.makeText(IgniteApplication.getInstance(), "我们不支持在模拟器上运行哦",
Toast.LENGTH_SHORT).show();
finish();
return;
&#125;

阅读全文 »
1…4567
Ken

Ken

Android,BlockChain Developer

38 日志
10 分类
34 标签
RSS
GitHub
Links
  • Go Blockchain
© 2016 — 2018 Ken
由 Hexo 强力驱动
|
主题 — NexT.Pisces v5.1.4