In Android 2.2 how can I remove - android

I am trying to do some function in Android 2.2.
How can I remove and the borders in white and gray that is shown in below picture?

set Activity's theme to #android:style/Theme.NoTitleBar, in manifest

Add this line to your manifest file where you have declared your activity.
<activity
android:name=".activityName"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
or progrmatically you can do it by adding
requestWindowFeature(Window.FEATURE_NO_TITLE);
this above line with onCreate method

In your oncreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); // put that line in your oncreate method
setContentView(R.layout.youlayout);
}

you just need to have an edit in manifest as follows
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
this line will not show tiltlebar and will be a fullscreen however if you wants to hide just the title bar than use
android:theme="#android:style/Theme.NoTitleBar"
by means yours manifest should look like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.android.some"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
you can acieve the same by programming as follows
requestWindowFeature(Window.FEATURE_NO_TITLE);

You can do it by two ways
1) Programatically :
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
2) Modifying AndroidManifest.xml file:
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
</activity>

Related

Not able to hide ActionBar (Android)

i am trying to hide ActionBar in SplashScreenActivity but i am not able to hide. it always showing.
i tried this: but not worked
protected 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.activity_splash);
or
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.activity_splash);
or
this unfortunately stop app
<application
android:name="info.androidhive.awesomewallpapers.app.AppController"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/FreeWallTheme">
<activity
android:name="info.androidhive.awesomewallpapers.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In you application's manifest file , set the following property in <application> TAG.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen
Set the following line in your theme:
<item name="windowActionBar">false</item>
Try putting a new theme tag inside activity like below:
<activity
android:name="info.androidhive.awesomewallpapers.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Translucent.NoTitleBar" >
Try this, it worked for me:
getSupportActionBar().hide();
You have to call it in the onCreate method

Launcher Activity is opening twice in my new SDK

I am recently facing a problem while creating new android application in both eclipse as well as android studio.
I am using same SDK in both eclipse and android studio.
When I create a new application and i simply run it. The launcher activity was getting loaded twice.
Means, I am getting MainActivity loading twice one on top of another.
OnCreate() method of my MainActivity also got invoked twice.
The code goes like follows
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("OnCreate Invoked");
}
}
Output
OnCreate Invoked
OnCreate Invoked
Can you please help me in resolving this issue.
Thanks in advance.
It seems you are getting multiple instance of your first activity.
Use this in manifest of 1st activity:
android:launchMode="singleTop"
If I set orientation programatically in onCreate - I can reproduce this issue.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
If needed, set activity orientation in the manifest file like this.
<activity
android:name=".MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

How does an android program understands which class or/and activity to call first?

As i am new to android programming, I don't know how to call a certain class and/or certain activity first.
For example i have two classes viz. 1) Login.java 2) Create.java and two xml files associated with them are activity_main.xml and create_new.xml respectively.
So how can i make Login.java run first with activity_main.xml as screen?
in login java use this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
in create java us this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_new);
in androidmanifest
<activity
android:name=".Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and another activities
<activity android:name=".MainActivity" ></activity>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.your.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.your.package.activity.Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.your.package.activity.Create"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
In this case, the intent-filter of LOGIN activity specifies that the intent with action of MAIN and category of LAUNCHER will be caught by it, aka it is where the application starts.
Afterwards,
public class Login extends Activity
{
//honestly I'd name this class LoginActivity and same in the XML
#Override
public void onCreate(Bundle saveInstanceState)
{
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_main);
}
....
}
Also look at this example to learn how to use Fragments:
NullPointerException accessing views in onCreate()
from the intent filters you decalre in the android manifest file of your project;see the image
You declare an intent filter in the activity tag something like shown in the image for making it the first activity of your application.and if there are other activities in your app having intent filters than you have to just change the capital letter MAIN to DEFAULT in the intent filter tag
You will find AndroidManifest file like in the following image in your project

Android Google Map API:Force Close Error

I have received forced closed error message on running the sample code of Google API.Is update a project is a solution to this type of project? If so then how to update project on window.The method given here don't work on my case.
Here is code
Filename:HelloGoogleMaps.java
package com.hellogooglemaps.practices;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class HelloGoogleMaps extends MapActivity {
/** Called when the activity is first created. */
#Override
protected boolean isRouteDisplayed(){
return false;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MapView mapView = (MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isLocationDisplayed(){
return true;
}
}
HelloGoogleMaps Manifest
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".HelloGoogleMapsActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HelloGoogleMaps" android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" />
<uses-library android:name="com.google.android.maps"/>
</application>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0_hYeORLgQUROOOr_RXN2TWG2u2pCDoBYfLCV_w"
/>
As you had mentioned in your code, You have only one Activity called HelloGoogleMaps and in your AndroidManifest you have declared two activities!! your HelloGoogleMapsActivity is useless. You are getting the error because you set HelloGoogleMapsActivity as the Launcher activity and this activity don't even exist!!
Solution:
change your AndroidManifest.xml like that and you will get your app work if you had managed to get the apikey for your map correctly:
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:name=".HelloGoogleMaps" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps"/>
</application>
After facing Force close Error many time what I have found is that these type of error is so common and come due to the undefined behavioral.Like when we declare Button and without assigning the view on it we use it on another function. It is also appear due to not handling the exception correctly. or Due to unavailable of resource your are trying to access in emulator like contact number. Best method to solve these type of problem is using log and printing some message on place where we feel confusing and using logcat.
In above case I had received force close error due to undefined behavior in HelloGoogleMapsActivity class

Android ActivityNotFoundException

I'm trying to create a very simple custom intent example. I've searched for this error and none of the forums have answers that work for me. Here are my files:
public class DemoImplicit extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void whenButtonIsClicked(View view) {
Intent intent = new Intent("com.example.action.NEW_ACTION"); //<<<<<<<
intent.addCategory("android.intent.category.DEFAULT"); //<<<<<<<
// Intent intent = new Intent("android.intent.action.VIEW");
// intent.addCategory("com.example.MY_CATEGORY");
startActivity(intent); //<<<<<<<
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demos" android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".SatisfyIntent" android:label="#string/app_name">
<intent-filter>
<!-- action android:name="android.intent.action.VIEW" / -->
<!-- category android:name="com.example.MY_CATEGORY" / -->
<action android:name="com.example.action.NEW_ACTION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
These two separate files are in two different Eclipse projects, but I make sure to load the project containing the intent-filter onto the emulator before loading the file containing the startActivity call onto the emulator. In any case, I always get an ActivityNotFoundException.
What am I doing wrong?
P.S. Here's the AndroidManifest.xml file for the project containing DemoImplicit.java:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demos"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".DemoImplicit"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
Fisrtly you shuld ensure that your AndroidManifest.xml file must have defined the DemoImplicit Activity in this.
As like this:<activity android:name=".DemoImplicit"/>
Also in your code you have aspecified the SatisfyIntent as a launcher Activity
<activity android:name=".SatisfyIntent" android:label="#string/app_name">
But here it seems like you have nothing like this in your Java Code.
So the Bottom line is that: Activity which you want to run must have defined in your AndroidManifest.xml file.

Categories

Resources