0.下載個demo,運行個sample,而後就出事了。新浪微博登陸提示"21338 sso package or sign error"html
簽名不對。MD5工具根據keystore生成簽名的。Demo的簽名是用官網的keystore生成的,而此時用的是Android Studio默認的debug.keystore。因此將其替換成新浪提供sample項目的keystore便可。java
1.Toolbar下有陰影。android
其實不算問題,但我就是不想有。。git
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" app:elevation="0dp" android:theme="@style/MyTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/MyTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout>
app:elevation="0dp"
2.如何實現下拉刷新?github
Google已經提供了SwipeRefreshLayout。api
3.上拉加載?app
http://blog.csdn.net/bboyfeiyu/article/details/39935329
ide
4.已經格式化了的時間字符串轉換成Date
工具
新浪微博api(http://open.weibo.com/wiki/2/statuses/public_timeline )裏,微博的建立時間是返回這樣的一串:this
Sun Dec 27 13:45:44 +0800 2015
我想將它轉換爲Date,以便與當前時間進行比較。
http://blog.csdn.net/fengyuzhengfan/article/details/40164721
構造一個SimpleDateFormat對象
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy");
用這個對象解析上面這串已經格式化了的時間
String dateString = "Sun Dec 27 13:45:44 +0800 2015"; Date date = sdf.parse(dateString);
但運行結果是
java.text.ParseException: Unparseable date: "Sun Dec 27 13:45:44 +0800 2015"
Google一下
這我的遇到的問題跟我同樣,但下面回答的老外說他也是這樣寫的,但運行沒問題。
You need to try SimpleDateFormat
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd"); System.out.println(sdf2.format(sdf.parse("Wed Jun 20 11:01:05 +0800 2012")));prints
2012/06/20You may also need to set an approriate timezone.
Thank you ,I tried your code but it throws java.text.ParseException: Unparseable date: "Wed Jun 20 11:01:05 +0800 2012" – topxebec Jun 20 '12 at 7:05
看看其餘相關的問題,發現漏了一個參數。
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy",Locale.US);
這樣寫,順利運行。
我猜想+0800這種表示時區的方式是美國的格式。可能不指定這個locale參數,默認就是當前系統的國家參數。因此上面這位stackoverflow的哥們運行沒問題。
並且貌似這種格式是標準格式,能夠直接這樣
Date createAt = new Date(sourceCreateAt);
來得到Date對象。
5. TextView顯示HTML元素
新浪微博api(http://open.weibo.com/wiki/2/statuses/public_timeline )裏,有一項是表示微博來源
"source"
:
"<a href="
http:
//weibo.com" rel="nofollow">新浪微博</a>"
要顯示a標籤的內容,而且讓textview點擊時,會連接到href,Google一下看有沒有html的解析器,發現textview自己就支持html的。
http://hunankeda110.iteye.com/blog/1420470
6.圓形頭像?
https://github.com/hdodenhof/CircleImageView
7. ?attr/text_body是什麼意思?
看AisenWeibo( http://www.oschina.net/news/62549/aisen-5-0-3 )源碼,有個地方定義textview風格,點進來是這樣的。
style.xml
<style name="TextBody"> <item name="android:textColor">?attr/text_body</item> <item name="android:textSize">16sp</item> </style>
attrs.xml
看到顏色定義成?attr/text_body,繼續點進去
<attr name="text_body" format="reference|color"/>
這裏只是定義了「text_body」的格式,沒有定義具體的值。
Google一下
http://stackoverflow.com/questions/7504967/can-someone-explain-the-attr
The
?attr/menuIconCamera
value means that an icon frommenuIconCamera
attribute of the current theme will be used.There must be a drawable assigned to the
menuIconCamera
attribute somewhere in thethemes.xml
file. If there're two themes with different values of this attribute then actual icon will depend on a theme which is currently used.The
attrs.xml
file is used to define custom attributes. Without this definition compiler will treat unknown attributes as erroneous.
大意是具體的值是在theme.xml定義的,attrs.xml只是定義格式。
也就是說?attr/text_body這種是根據當前的主題來決定具體的值。
8.ListView分隔條?
不但願ListView的每一個列表項有分隔條。
android:divider="@null"
listview的divider屬性設置爲@null便可