作者QQron (Run)
看板AndroidDev
標題[問題] 關於更換整個介面的fonts
時間Fri Jun 26 22:08:57 2015
想請問一下 關於整個介面更換自訂字體的部分
我參考的是這個部落格
http://www.cnblogs.com/brainy/archive/2012/05/30/2526538.html
創造出一個fontmanger,對整個介面使用自訂字體的部分
寫法fontmanger跟他一樣
public class FontManager {
想請問一下 關於整個介面更換自訂字體的部分
我參考的是這個部落格
http://www.cnblogs.com/brainy/archive/2012/05/30/2526538.html
創造出一個fontmanger,對整個介面使用自訂字體的部分
寫法fontmanger跟他一樣
然後在每個活動的oncreat部分,寫入以下code
//更換字體
ViewGroup systemContent = (ViewGroup)this.getWindow().getDecorView().findViewById(android.R.id.content);
ViewGroup content = null;
if(systemContent.getChildCount() > 0 && systemContent.getChildAt(0) instanceof ViewGroup){
content = (ViewGroup)systemContent.getChildAt(0);
}
FontManager.changeFonts(content, this);
這也是參考他的回文寫的,其實我這部分都一知半解
可是這樣會產生以下錯誤
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
小弟新手上路,可以請高手指點一下該如何修正處理嗎?感激不盡
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.163.19.48
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1435327741.A.F1B.html
推 corrupt003: content 為 null ? 06/27 01:03
→ QQron: 這問題修正好了,結果產生新的問題 06/27 02:41
我學原作者在活動中設個
public static ViewGroup getContentView(Activity act){
ViewGroup systemContent = (ViewGroup)act.getWindow().getDecorView().findViewById(android.R.id.content);
ViewGroup content = null;
if(systemContent.getChildCount() > 0 && systemContent.getChildAt(0) instanceof ViewGroup){
content = (ViewGroup)systemContent.getChildAt(0);
}
return content;
}
並在同個活動的onCreat寫下
//更換字體
FontManager.changeFonts(getContentView(this), this);
NULL pointer就修正完了,可是產生了新的問題
實機測試時,會黑屏一陣子,然後產生
Fatal signal 6 (SIGABRT), code -6 in tid 14503
這小段錯誤訊息,沒有更多的訊息提示了
可以請問一下該怎麼解決嗎?
※ 編輯: QQron (42.73.195.160), 06/27/2015 02:43:13
※ 編輯: QQron (42.73.195.160), 06/27/2015 02:43:39