I am new to android. I want to create a app with different theme for all the activities. I searched a lot for this but i cant find the correct solution.
Here the code
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sample.webservice" >
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.sample.webservice.Usermain"
android:label="#string/title_activity_usermain"
android:theme="#style/UserMainTheme"
android:parentActivityName="com.example.sample.webservice.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.sample.webservice.MainActivity" />
</activity>
</application>
</manifest>
Styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:background">#color/white</item>
<item name="android:windowBackground">#color/white</item>
<item name="android:colorBackground">#color/white</item>
</style>
<style name="UserMainTheme" parent="android:Theme.Holo.Light">
<item name="android:background">#color/white</item>
<item name="android:windowBackground">#color/white</item>
<item name="android:colorBackground">#color/white</item>
</style>
</resources>
activity_main.xml
<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=".MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:fontFamily="sans-serif"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/username"
android:id="#+id/textView" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/username"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="#string/password"
android:id="#+id/textView2" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/password"
android:layout_gravity="right"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/login"
android:id="#+id/login_button"
android:layout_marginTop="#dimen/login_top_margin"
android:layout_gravity="center_horizontal" />
</LinearLayout>
</RelativeLayout>
activity_usermain.xml
<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.example.sample.webservice.Usermain">
<TextView android:text="#string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
MainActivity.java
package com.example.sample.webservice;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button login = (Button) findViewById(R.id.login_button);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setContentView(R.layout.activity_usermain);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here the screen shot of output:
MainActivity Screen
Usermain Screen
the above two screens having the same theme. Please help me in this thanks in advance
I forgot to start activity with Intent. That's why the style is not applied.
have to change this
public void onClick(View v) {
setContentView(R.layout.activity_usermain);
}
with this one in MainActivity.java
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Usermain.class);
startActivity(intent);
}
Its working good.
brother i also made an activity that wasn't much complex either just to test this issue but i didn't need to initiate any code. as u have described in the answer. It is working fine for me. All i did was change my Android Manifest file a bit and styles.xml.
after only these 2 changes i was good to go
Related
i'm developing android App which is full-screen App,
in the main activity there are 2 buttons
The issue is when i click in the About button the pop-out activity appear
after click on dismiss the title bar appear in the main activity, see the screen capture:
The main activity
After clicking About button and clicking on dismiss
about_popout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="60"
android:background="#android:color/transparent"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:background="#drawable/about_shape"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12pt"
android:textColor="#FFFFFF"
android:text="It's a PopupWindow" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/common_ic_googleplayservices" />
<Button
android:id="#+id/btn_dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="Dismiss"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
activity_main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#ff5722"
android:orientation="vertical"
tools:context="com.game.circle.thecirclegame.MainMenu">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To the Game"
android:id="#+id/startButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_about"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20px"
android:layout_marginLeft="100px"
android:layout_marginRight="100px"
android:text="About"/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game.circle.thecirclegame">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainMenu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GamePanel"></activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
The class MainMenu.java where the title bar appears, after clicking btn_about
package com.game.circle.thecirclegame;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;
import android.app.ActionBar.LayoutParams;
public class MainMenu extends AppCompatActivity {
Button btn_startGame, btn_about;
final Context context = this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
setContentView(R.layout.activity_main_menu);
addListinerToButtons();
}
public void addListinerToButtons(){
btn_startGame = (Button)findViewById(R.id.startButton);
btn_about = (Button)findViewById(R.id.btn_about);
btn_startGame.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,GamePanel.class);
startActivity(intent);
}
});
btn_about.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater)
getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.about_popout, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
Button btn_dismiss = (Button)popupView.findViewById(R.id.btn_dismiss);
btn_dismiss.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btn_about, 50, -30);
}
});
}
}
i need to get red of the blue title bar.
You can remove the title bar forever by calling:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
before the setContentView(R.layout.x) in your activity class.
To make the app fullscreen, you can do:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Again, put the above code before the setContentView method.
And make sure, if you are doing this, you should extend your Activity class by Activity and not AppCompatActivity or any other class.
Problem solved.
Because i didn't continue using the popup window,
i create a new activity instead and make the button redirect from main menu to About activity
I recently started with Android application development and have come across an issue with the ActionBar. I am aware that this question has been asked a few times, and so I have made the changes necessary from what I can see from the other articles.
Currently, my main activity looks like this: image
As you can see, there is a blue bar at the top of the screen directly under the notification bar where an ActionBar is supposed to be. All of my app themes are (I believe) set to NoActionBar. I would like to get rid of this blue bar so that I can use the entire screen to put my contents.
My code is as follows:
Main_Activity.Java
package ryanpx2016.golftracker;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button regularScorePageActivityButton = (Button)findViewById(R.id.scoreSheetButton);
regularScorePageActivityButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
startActivity(new Intent(MainActivity.this, RegularScorePageActivity.class));
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context=".MainActivity">
<Button
style="?android:attr/buttonStyleSmall"
android:background="#drawable/scoresheet_button"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:text="#string/scoresheet_button"
android:id="#+id/scoreSheetButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:background="#drawable/course_buttons"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:text="#string/my_golf_courses_button"
android:id="#+id/myGolfCoursesButton"
android:layout_below="#+id/scoreSheetButton"
android:layout_alignStart="#+id/scoreSheetButton"
android:layout_marginTop="35dp" />
<Button
android:background="#drawable/course_buttons"
android:layout_width="185dp"
android:layout_height="wrap_content"
android:text="#string/my_minigolf_courses_button"
android:id="#+id/myMinigolfCoursesButton"
android:layout_marginTop="35dp"
android:layout_below="#+id/myGolfCoursesButton"
android:layout_centerHorizontal="true" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ryanpx2016.golftracker" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RegularScorePageActivity"
android:label="#string/title_activity_regular_score_page"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="ryanpx2016.golftracker.RegularScorePageActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
I believe this may have something to do with a toolbar, but then again, I don't necessarily know what I'm saying :D
Any and all help is greatly appreciated. Thanks!!
Delete this from your activity_main.xml :
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="#style/AppTheme.PopupOverlay" />
I've been tring for 2 days to get this to work but I couldn't,I keep getting this exception com.parse.ParseRequest$ParseRequestException: invalid session token.
I'm not an experienced android developper and it's my first time with parse so I'd appreciate it if you can post a detailed answer.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<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.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".ParseApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="#string/parse_app_id" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="#string/parse_client_key" />
<activity
android:name=".ParseStarterProjectActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".SignUp"
android:label="#string/title_activity_sign_up" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
SignUp.java
package com.parse.starter;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
public class SignUp extends Activity {
private Button sign_up_b;
private TextView email;
private TextView password;
private TextView password_conf;
private TextView firstName;
private TextView lastName;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_up);
sign_up_b = (Button)findViewById(R.id.email_sign_up_button);
email = (TextView)findViewById(R.id.email);
password = (TextView)findViewById(R.id.password);
password_conf = (TextView)findViewById(R.id.confirm_password);
firstName = (TextView)findViewById(R.id.first_name);
lastName = (TextView)findViewById(R.id.last_name);
sign_up_b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
attemptSignUp();
}
});
}
private void attemptSignUp(){
// Create the ParseUser
ParseUser user = new ParseUser();
// Set core properties
user.setUsername(email.getText().toString());
user.setPassword(password.getText().toString());
user.setEmail(email.getText().toString());
// Set custom properties
user.put("lName", lastName.getText().toString());
user.put("fName", firstName.getText().toString());
// Invoke signUpInBackground
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(com.parse.ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
//Intent i = new Intent(getBaseContext(),Splash.class);
//startActivity(i);
} else {
e.printStackTrace();
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sign_up, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
signup.xml
<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.parse.starter.SignUp">
<ScrollView android:id="#+id/sign_up_form" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="#+id/sign_up_infos" android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<EditText android:id="#+id/first_name" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_first"
android:maxLines="1"
android:singleLine="true" />
<EditText android:id="#+id/last_name" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_last"
android:maxLines="1"
android:singleLine="true" />
<EditText android:id="#+id/email" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_email"
android:inputType="textEmailAddress" android:maxLines="1"
android:singleLine="true" />
<EditText android:id="#+id/password" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_password"
android:inputType="textPassword"
android:maxLines="1" android:singleLine="true" />
<EditText android:id="#+id/confirm_password" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_confirm_password"
android:inputType="textPassword"
android:maxLines="1" android:singleLine="true" />
<Button android:id="#+id/email_sign_up_button" style="?android:textAppearanceSmall"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:text="#string/action_sign_up"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
I've tried the answer in this posts but I kept getting the same exception
com.parse.ParseRequest$ParseRequestException: invalid session token
For future reference all I had to do is uninstall the application from the emulator than run it again and the problem was solved.
You need to logout the user in Login\Signup view controllers.
Try this in viewDidLoad:
ParseUser.getCurrentUser().logOut();
I am new to Android dev and for my project, I am creating two seekbars. The first seekbar has a minimum of 50 and a maximum of 180 while the second seekbar has a minimum of 180 and a maximum of 400. I also added textview labels below each seekbar to show the current value of each. My code compiled fine without any errors and displayed fine on the Android emulator, but when I clicked on the slider to change the value of the seekbar, my app ended up crashing and saying, "Unfortunately, your project has stopped." Below is my code:
MainActivity.java
package com.example.myname.projectname;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.R.*;
public class MainActivity extends ActionBarActivity implements OnSeekBarChangeListener {
private SeekBar lowBar;
private SeekBar highBar;
private TextView lowtext;
private TextView hightext;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializevariables();
lowBar = (SeekBar)findViewById(R.id.lowbar);
highBar = (SeekBar)findViewById(R.id.highbar);
lowtext = (TextView)findViewById(R.id.lowval);
hightext = (TextView)findViewById(R.id.highval);
lowBar.setOnSeekBarChangeListener(this);
highBar.setOnSeekBarChangeListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void initializevariables(){
lowBar = (SeekBar) findViewById(R.id.lowbar);
highBar = (SeekBar) findViewById(R.id.highbar);
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
progress = 0;
int lowbarmin = progress + 50;
int highbarmin = progress + 180;
lowtext.setText(lowbarmin);
hightext.setText(highbarmin);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
}
activity_main.xml
<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=".MainActivity">
<EditText android:text="CGM Alarm System" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lowbar"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:indeterminate="false"
android:progress="0"
android:max="180"/>
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/highbar"
android:layout_below="#+id/lowbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="66dp"
android:layout_alignRight="#+id/lowbar"
android:layout_alignEnd="#+id/lowbar"
android:progress="0"
android:max="400"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="50"
android:id="#+id/lowval"
android:layout_below="#+id/lowbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="180"
android:id="#+id/highval"
android:layout_below="#+id/highbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myname.projectname"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myname.projectname.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>
Thank you in advance!
Your seekbar's minimum value is 50, you can not increase +50;
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
int lowbarmin = progress + 1;
int highbarmin = progress + 1;
lowtext.setText(lowbarmin);
hightext.setText(highbarmin);
}
Crash is probably because of these lines :
lowtext.setText(lowbarmin);
hightext.setText(highbarmin);
When you do this and the value of lowbarmin and highbarmin are integers, android looks for string resources with those values as their resourceId and it cannot find one.
So what you instead want to do is, pass string values to setText() :
lowtext.setText(Integer.toString(lowbarmin));
hightext.setText(Integer.toString(highbarmin));
I am a novice and I'm just creating a simple Android app in which there are 2 buttons that take you to different pages when clicked, which have different functions.
However, my app crashes on start-up, simply saying
Unfortunately [app name] has stopped
and I don't understand
As I have barely made any changes to my MainActivity.java, the code seems to be well written, and eclipse displays no errors... Any help, please? I have searched around Stack, but I can't find anything specific to this...
Here is my MainActivity.java:
package com.example.helper;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**Called upon when the user clicks the 'Abbreviations' button*/
public void listDefinitions (View view){
Intent intent = new Intent(this, ListDefinitions.class);
startActivity(intent);
}
/**Called upon when the user clicks the 'Assistant' button*/
public void openAssistant (View view){
Intent intent = new Intent(this, Assistant.class);
startActivity(intent);
}
}
Here is my activity_main.xml:
<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: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="com.example.legittest.MainActivity" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="#string/intro_title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="21.5sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
android:text="#string/module_selection"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/definitions_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:layout_marginLeft="34dp"
android:layout_marginTop="111dp"
android:text="#string/definitions"
android:onClick="listDefinitions" />
<Button
android:id="#+id/assistant_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/definitions_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:text="#string/assistant"
android:onClick="openAssistant" />
<TextView
android:id="#+id/definitions_explainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/definitions_button"
android:layout_centerHorizontal="true"
android:text="#string/definitions_info"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/greycolor" />
<TextView
android:id="#+id/pa_explainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/definitions_explainer"
android:layout_below="#+id/assistant_button"
android:text="#string/assistant_info"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/greycolor" />
</RelativeLayout>
My ListDefinitions.java & Assistant.java are untouched at this point.
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.theocratichelper"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="21" />
<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>
<activity
android:name=".ListDefinitions"
android:label="#string/title_activity_list_definitions"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
<activity
android:name=".PreachAssistant"
android:label="#string/title_activity_preach_assistant"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
</application>
</manifest>
It's your manifest, replace the "last" activity in your manifest by this :
<activity
android:name=".Assistant"
android:label="#string/title_activity_preach_assistant"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.theocratichelper.MainActivity" />
</activity>
Your class name is Assistant and not PreachAssistant i presume.
Just replace the last activity in Android Manifest by this.
<activity
android:name=".Assistant"
android:label="#string/title_activity_preach_assistant"
</activity>