我的活动中有一个ActionBar
,其中包含自定义字体和fontstyle:
public void setActionBar() {
SpannableString s = new SpannableString("Create a new goal");
s.setSpan(new TypefaceSpan(getApplicationContext(), "BebasNeue Regular.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
actionBar = getActionBar();
actionBar.setTitle(s);
int actionBarTitleId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
if (actionBarTitleId > 0) {
Log.i("LIFECYCLE", "actionBarTitleId: " + actionBarTitleId);
TextView title = (TextView) findViewById(actionBarTitleId);
if (title != null) {
Log.i("LIFECYCLE", "title: " + title);
title.setTextColor(Color.WHITE);
title.setTextSize(26);
}
}
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.drawable.icon);
}
我在onCreate()之后调用它。在活动中,用户可以将图像加载到ImageView中,当我打开相机并创建图像然后单击BACK或只需单击BACK而不创建图像以返回活动时,样式将重置为默认字体样式,字体变得小而黑。
这是我打开活动时的样子:
这是从相机回来后的样子:
我在活动中添加了生命周期回调方法,以找出问题所在,但事实证明我收到了所有日志消息(均在上面的代码中),因此标题应该与我打开时的样子完全一样活性。
生命周期方法:
@Override
protected void onStart() {
super.onStart();
Log.i("LIFECYCLE", "onStart");
}
@Override
protected void onResume() {
super.onResume();
Log.i("LIFECYCLE", "onResume");
setActionBar(); //tried putting this here instead in onCreate
}
@Override
protected void onPause() {
super.onPause();
Log.i("LIFECYCLE", "onPause");
}
@Override
protected void onStop() {
super.onStop();
Log.i("LIFECYCLE", "onStop");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.i("LIFECYCLE", "onDestroy");
}
当活动不再可见时,这是以onStop()开头的日志:
10-30 21:01:00.074: I/LIFECYCLE(29143): onStop
10-30 21:01:00.094: D/HardwareRenderer(29143): startTrimMemory(level >=TRIM_MEMORY_COMPLETE)
10-30 21:01:01.634: I/LIFECYCLE(29143): onStart //coming back from camera
10-30 21:01:01.634: I/LIFECYCLE(29143): onResume
10-30 21:01:01.654: I/LIFECYCLE(29143): actionBarTitleId: 16908901
10-30 21:01:01.654: I/LIFECYCLE(29143): title: android.widget.TextView{4201dd98 V.ED.... ......ID 0,0-289,52 #1020265 android:id/action_bar_title}
10-30 21:01:01.694: I/Adreno-EGL(29143): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.041_msm8974_LNX.LA.3.5.1_RB1_CL3304448_release_AU (CL3304448)
10-30 21:01:01.694: I/Adreno-EGL(29143): OpenGL ES Shader Compiler Version: E031.24.00.14
10-30 21:01:01.694: I/Adreno-EGL(29143): Build Date: 04/18/14 Fri
10-30 21:01:01.694: I/Adreno-EGL(29143): Local Branch:
10-30 21:01:01.694: I/Adreno-EGL(29143): Remote Branch: quic/LNX.LA.3.5.1_RB1.1
10-30 21:01:01.694: I/Adreno-EGL(29143): Local Patches: NONE
10-30 21:01:01.694: I/Adreno-EGL(29143): Reconstruct Branch: AU_LINUX_ANDROID_LNX.LA.3.5.1_RB1.04.04.02.048.041 + NOTHING
10-30 21:01:01.724: I/InputMethodManager(29143): [startInputInner] EditorInfo { packageName=com.example.blgui3, inputType=0x34001, imeOptions=0x48000005, privateImeOptions=null }, windowGainingFocus=android.view.ViewRootImpl$W@41d387f0, mServedView=android.widget.AutoCompleteTextView{41b8b620 VFED..CL .F....ID 30,15-1050,152 #7f080120 app:id/actv_name}