I am working on an android project. And I want to show / hide the custom title bar on Button click. This button is for media player (full screen size / custom screen size ) please help me.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main1);
ctx=this;
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title1);
// FrameLayout frameLayout = (FrameLayout) findViewById(R.id.menu);
// FrameLayout frameLayout2 = (FrameLayout) findViewById(R.id.menu1);
for hide custom title i am using using following code onClick()
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
This is will hide the action bar:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this will make him back:
this.requestWindowFeature(Window.FEATURE_ACTION_BAR);
Related
App crashing when using requestWindowFeature(Window.FEATURE_NO_TITLE);
When using the button to make it full screen which when tries to hide the Title bar the app crashes
static int vari = 0;
public void fsc(){
ib = (ImageButton) findViewById(R.id.fulls);
ib.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Full-Screen", Toast.LENGTH_LONG).show();
if(vari == 0)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
vari = 1;
}
});
I wanted to make it full screen (hiding both status and title bar) on the button press
Please note: this is also to be called to fragments
Check if you have the fullscreen theme set in the manifest?
//if not add this in your manifest
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
// Hide status bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Show status bar
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
What Android theme should be used if I want full screen activities with white backgrounds running on devices supporting API 14+?
try this in your oncreate
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
I want to add a group of elements (textbox, button, progress bar and text view) and have them appear dynamically when pressing a button in Android. At every button press I want to create a group of the elements and put them in an relative layout. Here is my oncreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// The add button to insert new downloading file
add = (Button) findViewById(R.id.button_add_url);
add.setOnClickListener(this);
// Swapping between pause and resume
pause = (Button) findViewById(R.id.button_pause_resume);
pause.setOnClickListener(this);
download = (Button) findViewById(R.id.button_download);
download.setOnClickListener(this);
// The progress is written here
text = (TextView) findViewById(R.id.textView2);
text.setTextColor(Color.WHITE);
progress = (ProgressBar) findViewById(R.id.progressBar1);
}
maybe it would've been easier if you create relative layout as xml containing those elements and then on button click you can inflate that layout to main layout like this (on your button onClick method):
LinearLayout mainLayout = (LinearLayout)findViewById(R.id.personal_data_root);
RelativeLayout addLayout = (RelativeLayout)View.inflate(this, R.layout.layoutcontainingelementsouwanttoaddonclick, null);
mainLayout.addView(addLayout);
I set the following property in application tag of manifeast file. but it hides both titlebar(Actionbar) and Statusbar.Here i want to hide only the statusbar.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
for hiding only status bar add this code in oncrete of activity:
// Hide the Status Bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
and remove android:theme="#android:style/Theme.NoTitleBar.Fullscreen" from manifest
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
add this code to begining of your activity
Try the following code snippet:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* add below 2 lines*/
getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
I am learning android 3.0.
Can any one tell How can add Image in Title bar in android 3.0?
In developer site they are telling by default it will come.but for me it is not coming.
Thanks in advance.
You will have to create Custom Title Bar Layout to add your own image in titlebar.And then you can use following code to assign the titlebar to your view
boolean customTitleSupported;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
if (customTitleSupported) {
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_tittlebar_layout);
}
setContentView(R.layout.main);
}
here custom_tittlebar_layout refers to your custom titlebar layout with image.