change White background during app launch - android

I want to get rid of the white color during the short period when my app is launching but the content isn't displayed, yet.
My main activity is :-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kam"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<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.kam.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>
</manifest>
how can replace white background to progress bar ?
Update :-
mainfest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kam"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<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.kam.StartPoint"
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.kam.MainActivity"/>
</application>
</manifest>
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/loading" />
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.67" />
</LinearLayout>
startpoint.class
public class StartPoint extends Activity{
ProgressBar progressBar;
private int progressBarStatus = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
progressBar = (ProgressBar)findViewById(R.id.progressBar1);
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
while(progressBarStatus < 5000){
StartPoint.this.runOnUiThread(new Runnable(){
public void run()
{
progressBar.setProgress(progressBarStatus);
progressBarStatus += 1000;
}
});
}
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openMainList = new Intent(StartPoint.this, com.example.kam.MainActivity.class);
startActivity(openMainList);
}
}
};
timer.start();
}
protected void onPause(){
super.onPause();
finish();
}
}
i will try but when open loading image and open main layout its show error

There a many tutorials and videos for creating Splash Screens, which should give you the desired results.
The basic steps are;
Create a splash image in the desired drawables folders.
Create a theme with your image in it
create an activity using the theme, and have that activity start your current main activity

Related

Android layout title bar is not visible

I have created xml layout file. And when I give it as content to my Activity the TITLE BAR IS NOT VISIBLE. How can I make it visible. I tried to use setTitle("Title");
protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
Bundle b = getIntent().getExtras();
int layoutId = b.getInt("layout");
Log.d("====>>>", " " + layoutId);
setContentView(layoutId);
setTitle("Title");
}
function in onCreate() method. I is not work. This is my xml file.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.universityapp.enrollee.FacultyInformationActivity"
android:scrollbars="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/text_faculty_information_agro"
android:textSize="15dp"
android:textAlignment="center"
/>
</RelativeLayout>
</ScrollView>
I start activity via ListView:
profListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
facultyInfoIntent = new Intent(getBaseContext(), FacultyInformationActivity.class);
Bundle b = new Bundle();
b.putInt("layout", facultyLayoutNames[position]);
facultyInfoIntent.putExtras(b);
startActivity(facultyInfoIntent);
}
Log.d("Selected faculty", facultiNames[position]);
}
});
This is my Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.universityapp.universityapp" >
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name="com.universityapp.common.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.universityapp.common.MenuActivity"
android:label="Главное меню" >
</activity>
<activity
android:name="com.universityapp.enrollee.ContacsActivity"
android:label="Наши контакты" >
</activity>
<activity
android:name="com.universityapp.enrollee.Map"
android:label="#string/title_activity_map" >
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name="com.universityapp.enrollee.MapsActivity"
android:label="#string/title_activity_maps" >
</activity>
<activity
android:name="com.universityapp.bachelor.PlatonusActivity"
android:label="#string/title_activity_platonus" >
</activity>
<activity
android:name="com.universityapp.database.DatabaseActivity"
android:label="#string/title_activity_database" >
</activity>
<activity
android:name="com.universityapp.enrollee.EnrUniversityInfo"
android:label="#string/title_activity_enr_university_info" >
</activity>
<activity
android:name="com.universityapp.enrollee.ProfessionsActivity"
android:label="#string/title_activity_professions" >
</activity>
<activity
android:name="com.universityapp.enrollee.FacultyInformationActivity"
android:label="#string/title_activity_faculty_information" >
</activity>
</application>
</manifest>
Change:
public class MainActivity extends Activity{
}
in your class file to:
public class MainActivity extends AppCompatActivity{
}
I found the answer! I have changed Activity to ActionBarActivity and it works!
To show the title bar you can use this in your onCreate:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
You can do it by doing this (as suggested by HafizWaleedHussain):
public void showTitle() {
try {
((View) findViewById(android.R.id.title).getParent())
.setVisibility(View.VISIBLE);
} catch (Exception e) {
}
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
If this didn't work then open your Android Manifest file and remove this line if it exist:
android:theme="#android:style/Theme.NoTitleBar"
Got o styles.xml and make a new style
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
<item name="android:windowNoTitle">false</item>
</style>
and call it from Manifest (You can also add other features inside item tags)
<activity
android:name=".st.activity.MyGoogleMap"
android:theme="#style/CustomWindowTitleBackground">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I removed the statement android:theme="#style/AppTheme" in the application tag and the bar started appearing
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
**android:theme="#style/AppTheme"**>

Android App stops when button clicked

I am trying to write an app that has 4 menu buttons on the main screen. On clicking this each menu button, a new screen should appear. At the moment I have only written code to cater for the first button to be clicked, but it the app crashes/stops.
I think the problem is that I don't have the activity of TheCompany declared in the Android Manifest file, but I don't know how I would do that.
I am writing the app in Eclipse and so far I have the following files/sets of code:
MainActivity.Java:
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View button = findViewById(R.id.TheCompany);
button.setOnClickListener(new OnClickListener(){
public void onClick (View v){
startIntent();
}
});
//getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// If your minSdkVersion is 11 or higher, instead use:
// getActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
/** Called when the user clicks the Company button */
private void startIntent() {
// Do something in response to button
Intent intent = new Intent(this, TheCompany.class);
startActivity(intent);
}
}
The Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="The Company"
android:id="#+id/TheCompany"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Services"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contacts" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Structure" />
</LinearLayout>
</LinearLayout>
Then I have the TheCompany Java file:
public class TheCompany extends Activity
{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.company);
}
}
The Android.Manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:icon="#drawable/logo"
android:name="com.example.myfirstapp.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>
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
Simply add this in your Manifest "application" tag :
<activity
android:name="com.example.myfirstapp.TheCompany"
android:label="#string/app_name" >
</activity>
You need to declare each activity in the manifest file.
The result is this :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:icon="#drawable/logo"
android:name="com.example.myfirstapp.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>
<activity
android:name="com.example.myfirstapp.TheCompany"
android:label="#string/app_name" >
</activity>
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
you did`t create any id like "TheCompany" in activity_main.xml, you have to declare id for button and then get the id using findViewById(...);
View button = findViewById(R.id.button1);

Android Splash Screen broken

i made a splash screen with this youtube video turtorial here ~> http://www.youtube.com/watch?v=IHg_0HJ5iQo
i saved my files and made sure they are there now when i send it to my device the splash screen does not show up.. i dont know why.
heres my activity_main.xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/back_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
</RelativeLayout>
here is my splash.xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/splash_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
heres my manafest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.idoser"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.idoser.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>
</manifest>
So after talking in chat, I see that the reason your splash screen isn't showing up is because you're not doing anything with the splash.xml layout file. If you don't inflate your splash layout or set it as a content view, then you'll never see it.
There are several ways to do this but this is the approach that I would take:
Create a SplashActivity
Make SplashActivity your launcher Activity.
Use a timer to start your main activity.
SplashActivity.java
package com.example.idoser;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
public class SplashActivity extends Activity {
AsyncTask<Object, Object, Object> mTimerTask;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
#Override
protected void onResume() {
super.onResume();
if(mTimerTask != null) {
mTimerTask.cancel(false);
mTimerTask = null;
}
mTimerTask = new AsyncTask<Object, Object, Object>() {
#Override
protected Object doInBackground(Object... params) {
try {
Thread.sleep(3000); /* 3 second splash screen */
} catch(Exception e) { }
return null;
}
#Override
protected void onPostExecute(Object result) {
super.onPostExecute(result);
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
};
}
#Override
protected void onPause() {
super.onPause();
if(mTimerTask != null) {
mTimerTask.cancel(false);
mTimerTask = null;
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.idoser"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.idoser.SplashActivity"
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.idoser.MainActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
Mind you this is not the best possible way to do this but it should at least get your splash screen showing and give you an idea of the direction you need to go.

i cannot see my custom progress dialog

I tried the following code for creating a custom progress dialog. But I am not getting the desired output.
Following is my MainActivity.java code
public class MainActivity extends Activity {
private ProgressDialog mProgressDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
protected Dialog onCreateDialog(int id) {
mProgressDialog = new ProgressDialog(MainActivity.this);
mProgressDialog.setIcon(R.drawable.alert_dialog_icon);
mProgressDialog.setTitle(R.string.select_dialog);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
return mProgressDialog;
} }
The strings.xml file as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="select_dialog">Sample</string>
<string name="select_dialog_show">List dialog</string>
<string name="app_name">Dialog</string>
</resources>
The activity_main.xml is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
</RelativeLayout>
The DialogManifest.xml is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.dialog"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="1"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.sample.dialog.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>
Hi please refer this URL
When you create an custom view you should give your custom layout to dialog like below
dialog.setContentView(R.layout.maindialog);

Nothing is displayed in screen after running android program

I have written an android application to display a list. Code has taken from an example. There is no error in compiling, but nothing is displayed on after running the application. Expecting you help to solve this problem thanks. Please find below code i used...
Main Activity
public class MainActivity extends ListActivity {
ArrayList<String> listItems=new ArrayList<String>();
ArrayAdapter<String> adapter;
int clickCounter=0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listItems.add("Hello");
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems);
setListAdapter(adapter);
}
public void addItems(View v) {
listItems.add("Clicked : "+clickCounter++);
adapter.notifyDataSetChanged();
}
}
mainactivity.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/addBtn"
android:text="Add New Item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="addItems"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
/>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testlistview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="android.app.ListActivity" />
</activity>
</application>
</manifest>
Please add the following intentfilter to the manifest:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Android needs this intent filter to know which activity to start.
You may have set the wrong content view in MainActivity.
Try to replace the setContentView statement with the following one:
setContentView(R.layout.mainactivity.xml);

Categories

Resources