Waychel

发现一个新世界


  • 首页

  • 关于

  • 归档

Maven引入本地Jar包并将其打包进War包中

发表于 2017-12-19

配置pom.xml,依赖本地Jar

1
2
3
4
5
6
7
<dependency>
<groupId>alipay</groupId>
<artifactId>alipay-sdk</artifactId>
<version>20170411150054</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/libs/alipay-sdk-java20170411150054.jar</systemPath>
</dependency>

配置Maven插件将本地Jar打包进War中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
<includeScope>system</includeScope>
</configuration>
</execution>
</executions>
</plugin>

Android 沉浸式状态栏键盘不受挤压布局解决方案

发表于 2017-04-12

上代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
/*| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION*/);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
/*| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION*/
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
// window.setNavigationBarColor(Color.TRANSPARENT);
LinearLayout linear_bar = (LinearLayout) findViewById(R.id.status_bar_ll);
linear_bar.setVisibility(View.VISIBLE);
//获取到状态栏的高度
int statusHeight = SystemUtil.getStatusBarHeight(this);
//动态的设置隐藏布局的高度
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) linear_bar.getLayoutParams();
params.height = statusHeight;
linear_bar.setLayoutParams(params);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* 通过反射的方式获取状态栏高度
* @return
*/
public static int getStatusBarHeight(Context context) {
try {
Class<?> c = Class.forName("com.android.internal.R$dimen");
Object obj = c.newInstance();
Field field = c.getField("status_bar_height");
int x = Integer.parseInt(field.get(obj).toString());
return context.getResources().getDimensionPixelSize(x);
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}

其中:linear_bar 为布局里面标题栏上面1dp大小占位

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/base_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<LinearLayout
android:id="@+id/status_bar_ll"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@color/main_theme_color"
android:orientation="vertical"
android:visibility="gone"/>

<LinearLayout
android:id="@+id/layout_head"
android:layout_width="match_parent"
android:layout_height="48dip"
android:background="@color/main_theme_color"
android:orientation="horizontal">
...

以上就实现了Android 沉浸式状态栏。

但如果你Activity底部有输入框,需要弹出键盘,上述方式会导致布局不受挤压键盘,直接遮挡住输入框,解决方案很简单,即在布局文件最开头加入:

1
android:fitsSystemWindows="true"

Android7.x找不到libsqlite.so 问题

发表于 2017-03-07

######原因:

一般某些聊天的SDK都依赖于libsqlite.so(环信、融云),不过由于这个包从来没有变化,使用的是系统默认提供的(/system/lib/)。在Android 6.x及以下的平台可以运行。
Android7.x执行更严格的安全检查,禁止使用系统目录的内容。所以如果希望在7.x以上版本,需要把系统目录的libsqlite.so拷贝出来,也放在自己app对应指令目录下。

解决方案:

下载下面链接的so文件,放到对应的文件夹下,如libs/armv7-abi/libsqlite.so,并注意你的gradle是否引用了这个目录,如 jniLibs.srcDirs = [‘libs’]

libsqlite.so

输入时键盘弹出,布局整体上移

发表于 2016-01-13

先上效果图

关键代码:
1.在AndroidManifest.xml设置对应的Activity:
android:windowSoftInputMode="adjustResize"
2.activity对应的布局:

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
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f2f2f2"
android:clipToPadding="false"
android:fitsSystemWindows="true">

<ScrollView
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:fillViewport="true"
android:scrollbars="none">

<RelativeLayout
android:id="@+id/sv_content_rl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
</RelativeLayout>

</ScrollView>

<ImageView
android:id="@+id/login_close_iv"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginLeft="17.5dp"
android:layout_marginTop="17.5dp"
android:background="@mipmap/w_back_title_click" />
//注册帐号
</RelativeLayout>

3.activity代码:

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
root = (RelativeLayout) findViewById(R.id.root_rl);
//键盘显示,触摸键盘以外隐藏键盘
findViewById(R.id.sv_content_rl).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
// imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
return false;
}
});
root.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
View focus = root.findFocus();
ScrollView sv = ((ScrollView) findViewById(R.id.sv));
sv.fullScroll(ScrollView.FOCUS_DOWN);

if (focus != null && focus instanceof EditText) {//保证滑动之后 焦点依然未变
focus.requestFocus();
}

int loc[] = new int[2];
View view = findViewById(R.id.regist_area);
view.getLocationOnScreen(loc);
if (getScreenHeight(MainActivity.this) - loc[1] < Math.abs(getScreenHeight(MainActivity.this) / 2 - loc[1])) {//无压缩状态
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.INVISIBLE);
}
}
});

附上源码:https://github.com/Waychel/LayoutAboveKeyBoard

另外,还可以自定义Layout通过onLayout()方法来实现、或可以在Activity内嵌DialogFragment,先记下,有空再写。

Studio本地引用aar

发表于 2016-01-13

  何为aar?大家都知道jar文件,如果你有一个Android Library项目,可以很导出jar文件,然后在其他项目中很方便的引用,aar和jar类似,区别就是一个Android Library项目导出的jar文件不能包含资源文件,比如一些drawable文件、xml资源文件之类的,所以这就有很大的限制,在gradle之前我们要引用带资源文件的Android Library必须要把整个library导入进来进行引用,但是有了gradle之后,Android Library项目可以直接导出成aar,然后其他项目像引用jar的方式直接方便的引用。

  一般使用官方的提供的库:如 android-support-v7-appcompat、android-support-design
在build.gradle添加:

1
2
3
4
5
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}

但这个是需要联网,从MavenCentral下载下来。
如何离线本地引用aar呢?
在app的build.gradle文件添加如下内容

1
2
3
4
5
repositories {
flatDir {
dirs 'libs' //this way we can find the .aar file in libs folder
}
}

之后添加一句gradle依赖便方便的引用了该library

1
2
3
dependencies {
compile(name:'design', ext:'aar')
}

即可。

1234…8
Waychel

Waychel

关注互联网、物联网、创业、产品、技术

36 日志
9 标签
© 2014 - 2022 Waychel
粤ICP备14032841号-1