[关闭]
@Tyhj 2017-02-24T12:27:02.000000Z 字数 3875 阅读 1362

Android小结

Android


本文固定链接:https://www.zybuluo.com/Tyhj/note/601593

加载本地Html

把HTML文件放到assets文件夹里面

  1. WebSettings webSettings = webView .getSettings();
  2. webSettings.setJavaScriptEnabled(true); //支持js
  3. webView.requestFocusFromTouch();//支持获取手势焦点,输入用户名、密码或其他
  4. webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); //提高渲染的优先级
  5. //设置自适应屏幕,两者合用
  6. webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
  7. webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
  8. webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件
  9. webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
  10. webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
  11. webView.setWebViewClient(new WebViewClient(){
  12. @Override
  13. public boolean shouldOverrideUrlLoading(WebView view, String url) {
  14. webView.loadUrl(url);
  15. return true;
  16. }
  17. });
  18. webView.loadUrl("file:///android_asset/signin.html");
  19. }

史上最全WebView使用:http://www.jianshu.com/p/3fcf8ba18d7f

加载GIF图片

项目地址:https://code.google.com/archive/p/gifview/
使用方法:http://www.codeceo.com/article/gifview-android-gif.html

  1. com.ant.liao.GifView gifView= (com.ant.liao.GifView) view.findViewById(R.id.gif);
  2. gifView.setGifImage(R.mipmap.gif1);
  3. gifView.setGifImageType(com.ant.liao.GifView.GifImageType.COVER);
  4. gifView.setShowDimension(900, 820);

设置渐变背景

在drawable文件夹下新建文件,直接设置为背景

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  3. <gradient
  4. android:startColor="@color/color2from"
  5. android:endColor="@color/color2to"
  6. android:angle="270"
  7. />
  8. <corners android:radius="0dp" />
  9. </shape>

按钮点击效果

  1. android:background="?android:attr/selectableItemBackgroundBorderless"

http://blog.csdn.net/tyzlmjj/article/details/50096777

支持MarkDown

项目地址:https://github.com/tyhjh/RichText

  1. //引用
  2. compile 'com.zzhoujay.richtext:richtext:2.0.13'
  3. //使用
  4. RichText.fromMarkdown(String str).into(TextView tv);

使用AndroidAnnotations

官网网站:https://github.com/androidannotations/androidannotations/wiki/AvailableAnnotations

  1. 打开appgradle
  2. apply plugin: 'com.android.application'
  3. apply plugin: 'android-apt'
  4. def AAVersion = '4.0.0'
  5. dependencies {
  6. apt "org.androidannotations:androidannotations:$AAVersion"
  7. compile "org.androidannotations:androidannotations-api:$AAVersion"
  8. }
  9. //打开工程的gradle
  10. classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

水平左右翻转动画

  1. ObjectAnimator animator=(ObjectAnimator) AnimatorInflater.loadAnimator(context,
  2. R.animator.likes);
  3. animator.setTarget(holder.ibLike);
  4. animator.start();
  5. <!-- 0-180度旋转动画-->
  6. <objectAnimator android:duration="1000"
  7. android:propertyName="rotationY"
  8. android:valueFrom="0"
  9. android:valueTo="180"
  10. xmlns:android="http://schemas.android.com/apk/res/android" />

调整Dialog的大小

  1. Dialog di = new Dialog(context);
  2. di.setCancelable(true);
  3. LayoutInflater inflater = LayoutInflater.from(context);
  4. View layout = inflater.inflate(R.layout.item_set_friends, null);
  5. di.setContentView(layout);
  6. di.create();
  7. Window dialogWindow = di.getWindow();
  8. WindowManager m = ((Activity) context).getWindowManager();
  9. Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
  10. WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
  11. p.width = (int) (d.getWidth() * 0.75); // 宽度设置为屏幕的0.65
  12. dialogWindow.setAttributes(p);
  13. di.show();

关于一些手机getData获取不到相机返回值的问题

  1. File file=new File(path,date);
  2. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  3. intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
  4. startActivityForResult(intent, TAKE_PHOTO);
  5. //获取返回值时候,直接获取文件
  6. File file=new File(path,date);

侧滑菜单

  1. //recycle 侧滑
  2. compile 'com.yanzhenjie:recyclerview-swipe:1.0.2'

可以根据RecycleView的每个item传入的值来设置不同的ViewType,然后根据ViewType来设置不同的布局,并且添加不同的侧滑菜单

侧滑菜单github地址

关于导入so包的问题

可以在 app/src/main 下面新建文件夹jniLibs文件夹,然后把文件放进去就好了,
也可以一起放在libs目录下,在app 的build.gradle的Android括号内加入

  1. sourceSets.main{
  2. //让AS识别libs下的.so第三方包
  3. jniLibs.srcDirs =['libs']
  4. }

方法是只保留一个包 armeabi,或者每一个包下面都要有相同的文件,
如果只保留了一个文件夹后出现找不到so文件的问题,那么在defaultConfig的括号内加入以下内容:

  1. ndk {
  2. // 加了其他的文件夹(比如 armeabi-v7a,x86等)可能会出问题
  3. abiFilters "armeabi"
  4. }

如果出现一大堆你都看不懂,也看不完的内容,也看不出来讲的是什么出错的,可以先到设置里面,在Build下的Instant Run下面把Enable Instant Run取消掉,然后再试一下。百度语音,地图什么的最容易出现这些问题了,真是累。
额,因为Sdk 23及以上获取权限和取消了一些包,所以可以把defaultConfig的括号内的 targetSdkVersion 改为22,试试。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注