android - requestWindowFeature(Window.FEATURE_NO_TITLE) exception - android

I am setting a specific activity full screen when the use hits a START button.
In this case the showStopButton() is called .
It's running fine. But if I insert
requestWindowFeature(Window.FEATURE_NO_TITLE);
then it crashes , stating that it should be call before adding content.
How should I handle it to set NO_TITLE w the FULL_SCREEN ??
private void showStopButton(){
// requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().findViewById(android.R.id.content).requestLayout();
// handle element visibility
((Button)findViewById(R.id.stopButton)).setEnabled(false);
((Button)findViewById(R.id.startButton)).setVisibility(View.GONE);
((Button)findViewById(R.id.stopButton)).setVisibility(View.VISIBLE);
((SeekBar)findViewById(R.id.seekBar1)).setVisibility(View.VISIBLE);
((Button)findViewById(R.id.resetButton)).setVisibility(View.GONE);
((Button)findViewById(R.id.saveButton)).setVisibility(View.GONE);
}
I have the reverse process when the START button is redisplayed , and it's running back fine
In this case I remove the fullscreen mode
private void showStartButton(){
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().findViewById(android.R.id.content).requestLayout();
....
}

it's so simple ... I just need to hide the ActionBar... then show it when back to standard screen...
private void showStopButton(){
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
ActionBar actionBar = getActionBar();
actionBar.hide();
getWindow().findViewById(android.R.id.content).requestLayout();

Use -public class MainActivity extends Activity- instead of -public class MainActivity extends ActionBarActivity-

So:
#Override
protected void onCreate(
final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Make this activity, full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Hide the Title bar of this activity screen
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
// MORE INIT STUFF HERE...
//img = (ImageView) findViewById(R.id.imgRandom);
//btnRandom = (Button) findViewById(R.id.btnRandom);
}

Try this one......
public class MainActivity extends Activity {
Context context;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}
}

Add this.
requestWindowFeature(Window.FEATURE_NO_TITLE);
before
super.onCreate(savedInstanceState);
setContentView(R.layout.your activity);

It could be like this :
public class MainActivity extends AppCompatActivity {
...
private final Handler handler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
I used the above codes in the example of police car lights and siren.When the application is started, the light animation starts automatically and the siren sounds in the background.
Source : Android police lights & siren

Related

Android unable to hide title bar

I have a fragment that shows a camera preview and a button, and in the activity for the fragment I'm trying to hide the title bar, but it doesn't work. The title bar still shows. In the activity:
#Override
public void onCreate(Bundle savedInstanceState) {
// Hide the window title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Hide the status bar and other OS-level chrome
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
}
I'm following the book Android Programming: The Big Nerd Ranch Guide.
#Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Make this activity, full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Hide the Title bar of this activity screen
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
...
}
In manifest change this
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"

Android activity with no title bar crashes?

When I use this code to make my activity with no title my app crashes, I have tried it using .xml or by coding
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main_menu);
}
I also tried:
getActionBar().hide();
MinSDK=14
TargetSDK:21
Any idea?
getSupportActionBar().hide();
did the trick

Unfortunately app has stopped in Android

I am new in Android.I get "Unfortunately app has stopped" when i run following code.
public class MainActivity extends Activity {
Button btn;
EditText edit;
#Override
protected void onCreate(Bundle savedInstanceState) {
btn=(Button)findViewById(R.id.button);
edit=(EditText)findViewById(R.id.text);
super.onCreate(savedInstanceState);
setContentView(R.layout.test_click);
btn.setOnClickListener(onClickList);
}
private OnClickListener onClickList= new OnClickListener() {
#Override
public void onClick(View v) {
btn.setText(edit.getText());
}
};
Wrong:
btn=(Button)findViewById(R.id.button);
edit=(EditText)findViewById(R.id.text);
super.onCreate(savedInstanceState);
setContentView(R.layout.test_click);
Issue:
You are trying to find views before setting layout to Activity. So call setContentView() first and then you can find whichever views you want.
Correct:
super.onCreate(savedInstanceState);
setContentView(R.layout.test_click);
btn=(Button)findViewById(R.id.button);
edit=(EditText)findViewById(R.id.text);
Currently you are accessing views from current Activity before setting layout for Activity .Call setContentView before accessing views from xml as:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_click); // set layout here
btn=(Button)findViewById(R.id.button);
edit=(EditText)findViewById(R.id.text);
btn.setOnClickListener(onClickList);
}
You should call findViewById() after you call setContentView().

ActionBarSherlock with fullscreen

Is there some way to hide status bar and keep action bar visible?
Yes, there is.
You should set FLAG_FULLSCREEN in your onCreate method of Activity.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}

How to set the application to fullscreen from an Intent, Not from the main activity

My Application Has 4 Tabs, Each tab creates a subview ( intent ) now I have a handler for options/menu button within each intent , of the menu items is "Toggle Fullscreen" this doesn't work as the intent isn't the parent view while the activity containing the TabHost is the parent View, Now I need to know how do I Set the whole app. to FullScreen mode or how to Refer to the Parent Activity to Set the full screen mode through it.
Here's a snippet of my code
public class MainActivity extends TabActivity {
public void toggleFullScreen(){
// This has the code to set App. to full screen
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent myIntent = new Intent(this, MywebviewActivity.class);
tabHost.addTab(
tabHost.newTabSpec("SomeName")
.setIndicator("Some Title")
.setContent( myIntents ));
Now I need to set fullscreen mode from "MywebviewActivity" not from my MainActivity
modify code in your MainActivity as following
Intent myIntent = new Intent(this, MywebviewActivity.class);
intent.putExtra("isFullScreen", true);
now in onCreate() method of MywebviewActivity write code as following
put "setContentView(R.layout.main);" method below of this code as following :
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=getIntent();
boolean isfullScreen = intent.getBooleanExtra("isFullScreen", false);
if(isfullScreen )
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.main);
}
not it will work
check this
add this in your webview activity
Intent i=getIntent();
if(i!=null)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

Categories

Resources