YOU'VE ENTERED A SIMPLE ANDROIDBLOG, WELCOME.

Develop And Improve。

极简天气开发日记Day07

Things have done

沉寂了几天没干活,突然感觉Material Design相当有意思,于是乎研究了几天的Material Design,效果还不错。把侧滑栏换了,完善了布局,加了反馈模块,总的来说比上一个版本成熟了很多。

实现方法

1.Material Design

通读了Google关于Material Design的一些资料,发觉要完全按照这个规范实现布局也挺不容易的,在别的demo里实现过后感觉像toolbar对于这个App来说意义并不大,所以只按自己的需求进行了改动。

首先,Gradle里加上这三句话

1
2
3
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'

然后在布局文件里将原来布局用CoordinatorLayout包裹,在最下面添加FloatingActionButton如下

1
2
3
4
5
6
7
8
9
10
11
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/codelab_fab_margin_bottom"
android:layout_marginRight="@dimen/codelab_fab_margin_right"
android:src="@drawable/ic_favorite_24dp"
app:elevation="6dp"
app:pressedTranslationZ="12dp"
card_view:fabSize="normal" />

同时,将原来三个未来天气预报用CardView包裹实现边框效果

主界面实现状态栏和导航栏透明,还要在主布局文件里预留出状态栏空间,实现这一改动需要Android4.4版本及以上

1
2
3
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

选择天气界面添加如下代码,同样在选择天气布局里预留状态栏空间

1
2
3
4
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

2.新的侧滑栏

原来的侧滑栏存在一个Bug,必须先通过点击按钮弹出侧滑栏后才能通过滑动弹出弹入,所以趁着这个机会一并换成原装的侧滑栏,在上面的修改基础上,主布局最外层用DrawerLayout嵌套,最后使用NavigationView绘制侧滑栏内容,使用了一个图片以及三个按钮,效果非常不错

http://pic.yupoo.com/333ddd/FPg5CTzX/ClEBD.jpg

3.关于和反馈模块

使用AlertDialog非常轻松的构建出了让人满意的效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
private void showDialog() {
new AlertDialog.Builder(ShowWeatherActivity.this).setTitle("关于")
.setMessage("感谢使用极简天气,欢迎到我的Github项目里Fork and Star^_^,如果想了解详细的开发过程,也欢迎来我的Blog逛一逛(。・`ω´・)")
.setPositiveButton("屈尊一逛", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri.parse(getString(R.string.Blog)); //指定网址
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW); //指定Action
intent.setData(uri); //设置Uri
ShowWeatherActivity.this.startActivity(intent); //启动Activity
}
}).setNeutralButton("围观Github", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri.parse(getString(R.string.Github)); //指定网址
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW); //指定Action
intent.setData(uri); //设置Uri
ShowWeatherActivity.this.startActivity(intent); //启动Activity
}
})
.show();
}

反馈模块使用的国外的一个服务商提供的jar包,轻量且迅速

简单的注册后获取ApiKey,按照官方示例进行操作即可,非常简单,经测试反馈非常迅速地发送到了注册邮箱里,强烈推荐

http://pic.yupoo.com/333ddd/FPg6kORH/egJ0t.jpg

Things to do?

经反馈貌似多次切换城市会出现OOM,把这个解决掉