i want to make a Login page for the app. however the activity is not showing its only a blank page with a single title bar with a app name that is there. i tried different themes but the problem remains the same.
here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="variofitness.com.schedulekeeper">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/img_logo"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".HomeActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.NoActionBar">
</activity>
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
And Here is my styles file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/white</item>
<item name="android:textColorPrimary">#color/lightBlue</item>
<item name="android:windowBackground">#color/white</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" />
<style name="ToolBarStyle" parent="">
<item name="android:background">#android:color/transparent</item>
<item name="titleTextAppearance">?android:textAppearanceLarge</item>
</style>
<style name="ThemeOverlay.MyApp.ActionBar" parent="ThemeOverlay.AppCompat.ActionBar">
<!-- Parent theme sets colorControlNormal to textColorPrimary. -->
<item name="android:textColorPrimary">#color/lightBlue</item>
</style>
</resources>
Here is my java code..
package variofitness.com.schedulekeeper;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
/**
* Created by vinod on 1/29/16.
*/
public class LoginActivity extends AppCompatActivity implements View.OnClickListener{
EditText edtUserName,edt_password;
TextInputLayout input_application_password,input_application_userName;
TextView txt_Forgot_Password;
Button btn_login,btn_request_For_signUp;
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.layout_login);
initializeComponents();
}
private void initializeComponents() {
input_application_password = (TextInputLayout)findViewById(R.id.input_application_password);
input_application_userName = (TextInputLayout)findViewById(R.id.input_application_userName);
edtUserName = (EditText)findViewById(R.id.edtUserName);
edt_password = (EditText)findViewById(R.id.edt_password);
txt_Forgot_Password = (TextView)findViewById(R.id.txt_Forgot_Password);
btn_login = (Button)findViewById(R.id.btn_login);
btn_request_For_signUp = (Button)findViewById(R.id.btn_request_For_signUp);
}
#Override
public void onClick(View view) {
switch (view.getId()){
case R.id.txt_Forgot_Password:
break;
case R.id.btn_login:
break;
case R.id.btn_request_For_signUp:
break;
default:
break;
}
}
}
can anyone help me to tell me what i am missing?
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
Replace this piece of code with
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
And you are good to go.
Related
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
Solution:
I tried everything available on internet and nothing really worked for me. Then I found a solution. I didnt have the values-v23 folder in my project. If you don't have that, DO IT! and add this in style.xml of the Values- v23 folder
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
</style>
</resources>
I had splash screen and slider which was overlaying the action bar and android studi somehow got confused and my actionbar was returning null. After 2 weeks of research I found a tiny issue which no one seem to point out. I edited the line
android:theme="#style/AppTheme">
with the actual theme i was using i.e
<android:theme="#style/Theme.AppCompat.Light.DarkActionBar">
It worked for me..
Question
I had this app working totally fine until I made some changes.
I reverted back all of the changes but now I am getting NUllPointerException on ActionBar
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setLogo(R.mipmap.icon);
ab.setDisplayUseLogoEnabled(true); //shows logo
ab.setDisplayShowHomeEnabled(true); //shows home page
}
else {
Toast.makeText(HomeScreen.this, "Feature not supported!", Toast.LENGTH_SHORT).show();
}
I put the if else statements to check where the problem was. It runs the else part only. The piece of Home Screen code is this
package com.example.dell.optasia;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.media.MediaPlayer;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.support.v4.view.GestureDetectorCompat;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Locale;
import static android.view.GestureDetector.OnDoubleTapListener;
import static android.view.GestureDetector.OnGestureListener;
import static com.example.dell.optasia.R.id.editText;
public class HomeScreen extends AppCompatActivity implements
OnGestureListener, OnDoubleTapListener {
//used for text to speech
TextToSpeech ttsobject;
int result;
TextView et;
String text;
String texttoplay;
//uptil here
private GestureDetectorCompat GestureDetect;
private static TextView Viewtext;
//used for speech to text
public static final int REQUEST_OK = 1;
public static TextView finalRes;
public static ImageView imgBtn;
//uptill here
public MediaPlayer mp1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
mp1 = MediaPlayer.create(HomeScreen.this, R.raw.startup);
mp1.start();
ActionBar ab = getSupportActionBar();
if (ab != null) {
ab.setLogo(R.mipmap.icon);
ab.setDisplayUseLogoEnabled(true); //shows logo
ab.setDisplayShowHomeEnabled(true); //shows home page
}
else {
Toast.makeText(HomeScreen.this, "Feature not supported!", Toast.LENGTH_SHORT).show();
}
//for tap and hold and all other gestures
Viewtext = (TextView) findViewById(R.id.textView);
//onlongpress code needs this
GestureDetect = new GestureDetectorCompat(this, this);
GestureDetect.setOnDoubleTapListener(this);
//text to speech code here
et = (TextView) findViewById(editText);
ttsobject = new TextToSpeech(HomeScreen.this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
result = ttsobject.setLanguage(Locale.UK);
} else {
Toast.makeText(HomeScreen.this, "Feature not supported!", Toast.LENGTH_SHORT).show();
}
}
});
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
package="com.example.dell.optasia">
<uses-sdk android:minSdkVersion="11" />
<application
android:allowBackup="true"
android:icon="#mipmap/icon"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HomeScreen">
<intent-filter>
<action android:name="com.example.dell.optasia.HomeScreen" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".AboutUs">
<intent-filter>
<action android:name="com.example.dell.optasia.AboutUs" />
<category android:name="android.intent.category.About" />
</intent-filter>
</activity>
<activity android:name=".Help"></activity>
</application>
Style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">true</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>
#Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout...);
// experiment with the ActionBar
ActionBar actionBar = getSupportActionBar();
}
Here is my preference activity:
package com.example.hms.test;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class PrefsActivity extends PreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
}
here I want to show an actionbar with name settings and a back button to home
You should do couple of things:
Add the following to your onCreate of PreferenceActivity:
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Override onOptionsItemSelected in PreferenceActivity:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId())
{
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
change the <activity> tag in manifest for your PreferenceActivity to look something like this:
<activity
android:name=".PrefsActivity"
android:label="#string/title_activity_settings"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.MainActivity" />
</activity>
Finally put android:launchMode="singleTop" in your MainActivity <activity> tag in manifest:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The answer Pooya gave won't work for a PreferenceActivity. Instead make your class extend AppCompatActivity, and use a PreferenceFragment to load up the preference. Here is my code for settings:
public class MyPrefsActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
public static class MyPreferenceFragment extends PreferenceFragment {
#Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}
Put the activity in your AndroidManifest.XML:
<activity android:name=".MyPrefsActivity"
android:label="Preferences"
android:theme="#style/AppTheme"/>
And now you can start the settings activity using an intent in my Main Activity (or whichever parent activity you have) as normal:
Intent prefsIntent = new Intent(activity, MyPrefsActivity.class);
activity.startActivity(prefsIntent);
I needed different action bar menu items in my activities so I created my MainActivity with a singleTop launchMode. That was great for getting my child activity's action bar set up, but it left my preferences activity without an action bar.
In the end, the key was in making sure the MainActivity theme had a parent of
Theme.AppCompat.Light.NoActionBar:
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:theme="#style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and the SettingsActivity theme had the parent Theme.AppCompat.Light.DarkActionBar:
<activity
android:name=".SettingsActivity"
android:label="#string/title_activity_settings"
android:theme="#style/SettingsTheme"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="net.deatrich.app.bodyandminddbt.MainActivity" />
</activity>
In styles.xml
<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>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="SettingsTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
There's probably a better way to style it but this works.
For anyone else reading, also remember to derive your SettingsActivity from AppCompatPreferenceActivity:
SettingsActivity.java:
public class SettingsActivity extends AppCompatPreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// I'm displaying a fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new GeneralPreferenceFragment())
.commit();
setupActionBar();
}
private void setupActionBar() {
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
if (!super.onMenuItemSelected(featureId, item)) {
NavUtils.navigateUpFromSameTask(this);
}
return true;
}
return super.onMenuItemSelected(featureId, item);
}
...
okay. now you still trouble then i have unique solution for you which work 100% with just minor changes.
so first of all create one style for only settings activity.
here is my toolbar styles code.
<style name="Toolbar_settings_style" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorControlNormal">#color/appTitleTextColor</item>
</style>
and here is my stlyes.xml looks like
<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>
<item name="android:colorControlNormal">#color/appTitleTextColor</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" />
<style name="Toolbar_settings_style" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:colorControlNormal">#color/appTitleTextColor</item>
</style>
</resources>
yes. you noticed i have create duplicate styles(appTheme and Toolbar_settings_style both are same styles attribute) for only settingsActivity.
it is very important to create duplicate styles.
Now go to your settingsActivity and paste below code inside onCreate().
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
After placing above code now my SettingsActivity looks like
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.RingtonePreference;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.MenuItem;
import settingspreferences.AppCompatPreferenceActivity;
public class User_Settings extends AppCompatPreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// load settings fragment
getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit();
}
public static class MainPreferenceFragment extends PreferenceFragment {
#Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
// gallery EditText change listener
bindPreferenceSummaryToValue(findPreference(getString(R.string.key_gallery_name)));
// notification preference change listener
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
// onBackPressed();
}
return super.onOptionsItemSelected(item);
}
private static void bindPreferenceSummaryToValue(Preference preference) {
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
PreferenceManager
.getDefaultSharedPreferences(preference.getContext())
.getString(preference.getKey(), ""));
}
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
*/
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
#Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String stringValue = newValue.toString();
if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
preference.setSummary(
index >= 0
? listPreference.getEntries()[index]
: null);
} else if (preference instanceof RingtonePreference) {
// For ringtone preferences, look up the correct display value
// using RingtoneManager.
if (TextUtils.isEmpty(stringValue)) {
// Empty values correspond to 'silent' (no ringtone).
preference.setSummary(R.string.pref_ringtone_silent);
} else {
Ringtone ringtone = RingtoneManager.getRingtone(
preference.getContext(), Uri.parse(stringValue));
if (ringtone == null) {
// Clear the summary if there was a lookup error.
// preference.setSummary(R.string.summary_choose_ringtone);
} else {
// Set the summary to reflect the new ringtone display
// name.
String name = ringtone.getTitle(preference.getContext());
preference.setSummary(name);
}
}
} else if (preference instanceof EditTextPreference) {
if (preference.getKey().equals("key_gallery_name")) {
// update the changed gallery name to summary filed
preference.setSummary(stringValue);
}
} else {
preference.setSummary(stringValue);
}
return true;
}
};
}
}
Now let's come to real important part.
go to manifest.xml file and find your settingsActivity and paste below code.
<activity android:name=".User_Settings"
android:theme="#style/Toolbar_settings_style"></activity>
so here is my AndroidManifest.xml looks like
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mypackage">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!-- -->
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- <intent-filter> -->
<!-- <action android:name="android.intent.action.SEARCH" /> -->
<!-- </intent-filter> -->
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
<activity android:name=".Add_Items" />
<activity android:name=".Product_details_view" />
<activity
android:name=".editProducts"
android:parentActivityName=".Product_details_view" />
<activity android:name=".User_Settings"
android:theme="#style/Toolbar_settings_style"></activity>
</application>
</manifest>
This is all you need to shows Toolbar on settingsActivity.
I am trying to create my first Android app with a WebView. The last issue I am trying to resolve is to have the WebView in fullscreen with no title bar and no action bar.
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.domain.butlerv2">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<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>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
My MainActivity:
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
public class MainActivity extends AppCompatActivity {
String answer;
private GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
ConnectivityManager cm = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (null != activeNetwork) {
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
answer = "You are connected to a WiFi Network";
if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
answer = "You are connected to a Mobile Network";
} else
answer = "No WIFI Connectivity";
Toast.makeText(getApplicationContext(), answer, Toast.LENGTH_LONG).show();
WebView webView = (WebView)
findViewById(R.id._webview);
WebSettings webSettings = webView.getSettings();
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.domain.com/app/index.php");
webView.setWebViewClient(new MyBrowser());
webView.requestFocus(View.FOCUSABLES_ALL);
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
#Override
public void onStart() {
super.onStart();
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW,
"Main Page",
Uri.parse("android-app://com.domain.butlerv2/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
#Override
public void onStop() {
super.onStop();
Action viewAction = Action.newAction(
Action.TYPE_VIEW,
"Main Page", shown.
Uri.parse("http://host/path"),
Uri.parse("android-app://com.domain.butlerv2/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
private class MyBrowser extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
My Style
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 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.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="generalnotitle" parent="ThemeOverlay.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
</resources>
When I run the App on a Android phone the Title and Action bar are displayed. Can anyone see what I am doing wrong.
I have read so many Posts and tech papers all of which are different which has totally confused me.
Can you help.
Regards
Do this in Activity
if (Build.VERSION.SDK_INT < 16) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else
{
View decorView = getWindow().getDecorView();
//Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
}
and do the following in AndroidManifest
<activity
......................................
android:screenOrientation="portrait" <!--if you want to lock orientation-->
android:theme="#style/Theme.AppCompat.NoActionBar"
..................................... >
</activity>
Hope this solve your issue,
Change you AndroidManifest.xml theme from,
android:theme="#style/AppTheme.NoActionBar"
TO
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen"
I am developing an android app in matrial design.I am trying to use toolbar as the action bar of my app.but when run app i crasging & get the errror.
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
I have already gone through these links but not working
link link2
style.xml
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDarker</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<color name="primary">#457C50</color>
<color name="primaryDarker">#580C0C</color>
MianActivity.java
public class MainActivity extends ActionBarActivity {
Toolbar toolbar;
DrawerLayout mDrawerLayout;
FrameLayout mainView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
mainView=(FrameLayout)findViewById(R.id.frame_container);
ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
toolbar,
R.string.app_name,
R.string.app_name
)
{
public void onDrawerClosed(View view)
{
super.onDrawerClosed(view);
invalidateOptionsMenu();
syncState();
}
public void onDrawerOpened(View drawerView)
{
super.onDrawerOpened(drawerView);
invalidateOptionsMenu();
syncState();
}
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// TODO Auto-generated method stub
super.onDrawerSlide(drawerView, slideOffset);
mainView.setTranslationX(slideOffset * drawerView.getWidth());
mDrawerLayout.bringChildToFront(drawerView);
mDrawerLayout.requestLayout();
}
};
mDrawerLayout.setDrawerListener(actionBarDrawerToggle);
//Set the custom toolbar
if (toolbar != null){
setSupportActionBar(toolbar);
}
actionBarDrawerToggle.syncState();
}
}
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0"
>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:name="com.example.myapp.app.AppController"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".Login"
android:label="#string/app_name"
android:windowSoftInputMode="stateVisible|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.myapp.MainActivity" >
</activity>
</application>
</manifest>
Use <item name="windowActionBar">false</item>
instead of
<item name="android:windowActionBar">false</item> inside your style.xml
style.xml
<style name="AppTheme" parent="AppTheme.Base" />
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDarker</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
<color name="primary">#457C50</color>
<color name="primaryDarker">#580C0C</color>
When you use Theme.AppCompat.Light.NoActionBar, you can delete the following two lines (the equivalent AppCompat versions are added for you):
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
I have my values-v11/styles.xml file as follows, but the ActionBar won't show on my Nexus 5 (API 19). It manages to style the TextView and background, so the Theme is being set, just not with the ActionBar. What's going wrong?
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="android:textViewStyle">#style/AppTheme.TextView</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/ab_solid</item>
</style>
<style name="AppTheme.TextView" parent="android:Widget.TextView" >
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">10dp</item>
<item name="android:gravity">center</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
</style>
<style name="AppTheme.TextView.Header">
<item name="android:textColor">#666666</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.lobsterdoodle.kkworkhours.app" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="uk.lobsterdoodle.kkworkhours.app.WeekActivity"
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>
MainActivity.java
package uk.lobsterdoodle.kkworkhours.app;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TableRow;
public class WeekActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule);
...some non-actionbar related stuff...
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.week, 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);
}
}