Android activity with no title bar crashes? - android

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

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 - requestWindowFeature(Window.FEATURE_NO_TITLE) exception

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

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);
}

Custom title bar in PreferenceActivity?

I am using a custom title bar for my all activities but i can use this in PreferenceActivity.
All i can do in PreferenceActivity is this:
#Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences3);
My title bar in preference activity stay always grey without any text but other activities works very well this code. What i can do to solve my problem??
put getWindow().... after super and addPreferencesFromResource... so order should be:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences3);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_bar);
p.s. credits to original author #jeffrey-blattman following my previous answer here..

Android Development: Text contain

i have a editText, so how do i check if the editText contain like "http://www."?
Is this possible to see if a component contain a specific string?
Thank-you
PS. is it also possible to change android:theme(like no title) at runtime?
IIRC the titlebar needs to be removed in the Activity onCreate before you call setContentView.
I use
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
As for the text search use
String.contains("http://www");
For Example
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(tag, "onCreate");
main = this;
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);

Categories

Resources