问题
I am have a facebook like sliding menu bar in my app in which the two content and main layout of the app is handled by a Custom layout class.
I want to remove the titlebar of my app
Issue:
Even though I place
android:Theme.Light.NoTitleBar
in my manifest there is a blank space of title bar. Due to which my whole layout is pushed downwards.
I have tried using
requestWindowFeature(Window.FEATURE_NO_TITLE);
and
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
but still the titlebar space is not removed.
This is how the app looks like
I think this is caused due to the Custom LinearLayout class which holds the main sliding layout. But I am unable to remove the titlebar space from the custom layout class. Suggest a better solution.
Custom Layout Class
public class MainLayout extends LinearLayout {
public MainLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MainLayout(Context context) {
super(context);
}
// Overriding LinearLayout core methods
// layout based on the children
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
mainLayoutWidth = MeasureSpec.getSize(widthMeasureSpec);
menuRightMargin = mainLayoutWidth * 10 / 100;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
menu = this.getChildAt(0);
content = this.getChildAt(1);
content.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return MainLayout.this.onContentTouch(v, event);
}
});
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
if(changed) {
LayoutParams contentLayoutParams = (LayoutParams)content.getLayoutParams();
contentLayoutParams.height = this.getHeight();
contentLayoutParams.width = this.getWidth(); LayoutParams menuLayoutParams = (LayoutParams)menu.getLayoutParams();
menuLayoutParams.width = this.getWidth() - menuRightMargin;
}
menu.layout(left, top, right - menuRightMargin, bottom);
content.layout(left + contentXOffset, top, right + contentXOffset, bottom);
}
}
回答1:
u can specify directly in the manifest file of the activity
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
回答2:
Finally I was able to remove the titlebar space. As it turns out, including this tag
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
on application in manifest made the app fullscreen and corrected the issue. But I wanted the status bar to be visible in my app. So I had to compromise the status bar on the android versions in which the titlebar space was not reduced and let it be same on other versions. So here is how I resolved it.
in Manifest, I kept the code as it is
android:theme="@android:style/Theme.Light.NoTitleBar"
to remove the titlebar in the app
and in the activity which used the custom linear layout I checked the android version and kept the app fullscreen on versions less than and equal to Gingerbread.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
回答3:
Try this in your manifest file
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
回答4:
Add the android:theme property to your AndroidManifest.xml:
<application android:theme="@android:style/Theme.NoTitleBar">
回答5:
Hope this may help you.
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
回答6:
It seems that Theme.NoTitleBar
only works when applied to the whole application, not the activity itself. So put it in the application tag (in the manifest):
<application android:theme="@android:style/Theme.NoTitleBar">
Then, add any custom style you have to each activity.
Hope it helps.
回答7:
In value\style.xml define name and themes e.g,
Then goto your androidmainfest.xml add within activity like.. android:theme="@style/NoActionBar"
来源:https://stackoverflow.com/questions/20323137/android-theme-notitlebar-doesnot-work