我已经自定义了默认标题栏,它在 2.x、3.x 设备中按预期显示,但在 4.x 设备中没有显示。
在设备 2.2 上:
在设备 4.1.2 上:
这是onCreate里面的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView localTextView = (TextView) getWindow().findViewById(
android.R.id.title);
if (localTextView != null) {
ViewParent localViewParent = localTextView.getParent();
if ((localViewParent != null)
&& ((localViewParent instanceof FrameLayout))) {
View localView = ((LayoutInflater) getSystemService("layout_inflater"))
.inflate(R.layout.logout_button, null);
UIImageButton localUIImageButton = (UIImageButton) localView
.findViewById(R.id.logoutButton);
Rect localRect = new Rect();
Window localWindow = getWindow();
localWindow.getDecorView().getWindowVisibleDisplayFrame(
localRect);
int i = localRect.top;
int j = localWindow.findViewById(android.R.id.title).getTop() - i;
PrintStream localPrintStream = System.out;
Object[] arrayOfObject = new Object[1];
arrayOfObject[0] = Integer.valueOf(j);
localPrintStream.printf("%d", arrayOfObject);
localUIImageButton.setMaxHeight(j);
((FrameLayout) localViewParent).addView(localView);
}
}
}
这是清单代码:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我希望 4.x 设备中的标题栏与 2.x 中的类似。