ActionBarSherlock with fullscreen - android

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

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

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

hide activity name from action bar just in time of creation

Just in time of creation and for about one second or less the action bar shows the name of activity as declared in manifest. Is there any way to avoid this? Of course when activity is created i change programmatically the title.The manifest:
<activity
android:name="com.abc.HomeActivity"
android:screenOrientation="portrait"
android:label="Home"
android:icon="#drawable/x_logo">
</activity>
and code from fragment which is shown by activity. I change the title of action bar based on what fragment is shown.
((ActionBarActivity) getActivity()).getSupportActionBar().setTitle("variable name");
from activity:
super.onCreate(savedInstanceState);
getSupportActionBar().setTitle("");
If hiding the activity name means simply avoiding the text, then call the following in onCreate of your Activity:
getActionBar().setTitle(null); //if using ActionBar theme
setTitle(null); //if using standard theme
Update
#Override
protected void onCreate(Bundle savedInstanceState) {
...
final CharSequence title = getActionBar().getTitle();
getActionBar().setTitle(null);
//sets the title again after 1 second delay
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
getActionBar().setTitle(title);
}
}, 1000);
}
Use this line to hide a name of activity this.requestWindowFeature(Window.FEATURE_NO_TITLE);
just after onCreate.
Example.
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.serverfilelist);

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..

Categories

Resources