Disable a Android Title - android

1.Hello , i am trying to build a webView Full Screen App
But i can't understand how to disable the title bar
I change the theme in my manifest to this : Android:theme="#style/Theme.AppCompat.NoActionBar" >`
But that still keep showing me that Title .
2.From sdk 6 there is a like a email icon on the right bottom
of the app,there is way to disable that too ?
Thanks for all the help !!
code :
Manifest
:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.omermalka.webview" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.NoActionBar" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
main Activity :
package com.example.omermalka.webview;
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.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
/*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});*/
WebView webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyBrowser());
webView.loadUrl("https://pizzahut.co.il");
}
private class MyBrowser extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
Activity.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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main" tools:context=".MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView"
android:layout_alignParentStart="true" />
</RelativeLayout>
Thanks again to all the helpers

You can use requestWindowFeature(Window.FEATURE_NO_TITLE); in your activity before setContentView(LayoutId); to hide title.
Note:
Reference to this answer in AppCompact and ActionBarSherkock libraries you should put requestWindowFeature(Window.FEATURE_NO_TITLE); before super.onCreate();.
Or
you can put this code into styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
</resources>
and in your manifest file put below code in your activity tag
android:theme="#style/AppTheme.NoActionBar"
Like
<activity
android:name=".RSSActivity"
android:label="#string/title_activity_rss"
android:theme="#style/AppTheme.NoActionBar" >
</activity>

Related

Android app for a responsive web site crashes on load up on real phone

This is my first attempt at Android coding. We have a responsive web site and I call myself writing the code for an android app so that people and simply click on the icon after downloading the app and hit our website. On the Simulator, the app works fine on the various test phone, but when I upload APK for distribution and someone downloads and tries to run it, it crashes even before the splash screen is seen. Can some one please look at my code and tell me what's wrong. It seems to only crash on Android software version 6.0 or higher. On the old phones and tablets it run fine. Here are copies of my "SplashScreenActivity.java, my MainActivity.java, and my AndroidManifest.xml from Android Studios version 3.2.1. Any help would be appreciated.
SplashScreenActivity.java
package com.wastefreemail.wfmconnect;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class SplashScreenActivity extends AppCompatActivity {
private int SLEEP_TIMER = 3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash_screen);
getSupportActionBar().hide();
LogoLauncher logoLauncher = new LogoLauncher();
logoLauncher.start();
}
private class LogoLauncher extends Thread{
public void run(){
try{
sleep(1000 * SLEEP_TIMER);
}catch(InterruptedException e){
e.printStackTrace();
}
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
SplashScreenActivity.this.finish();
}
}
}
MainActivit.java
package com.wastefreemail.wfmconnect;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
public WebView web1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
WebView web1 = (WebView)findViewById(R.id.web1);
WebSettings webSettings = web1.getSettings();
webSettings.setJavaScriptEnabled(true);
web1.loadUrl("https://www.wastefreemail.com");
web1.setWebViewClient(new WebViewClient());
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wastefreemail.wfmconnect">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<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">
</activity>
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
try this,
manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.chetan.testapp">
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.wastefreemail.wfmconnect;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
public WebView web1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
web1 = (WebView)findViewById(R.id.webView);
WebSettings webSettings = web1.getSettings();
webSettings.setJavaScriptEnabled(true);
web1.loadUrl("http://www.wastefreemail.com/");
web1.setWebViewClient(new WebViewClient());
}
}
xml
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Hope it's help full.
Looks like there may be a problem in your splashscreen activity. Try below code and let me know for further updates.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashScreenActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
},5000); //here 5000 represents 5 seconds. Change this according to your need.
}
Edit
If even that doesn't work then make a new style in your styles.xml file.
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And apply this style to your activity in your manifest.xml file.
<activity
android:name=".SplashScreenActivity"
android:theme="#style/AppTheme.NoActionBar" />
EDIT
That SupportActionBar method is throwing a Null Pointer exception. Use this code in your splash activity. It will resolve the issue.
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash_screen);
try{
getSupportActionBar().hide();
} catch (NullPointerException e){
e.printStackTrace();
}

Remove Title bar from splash screen

How can remove title bar from splash screen?
I have two activity ( Main Activity and splash screen avtivity ) . I uesd the code requestWindowFeature(Window.FEATURE_NO_TITLE); for the two activity to hide the title bar. so, it is removed from main activity but not removed from splash screen activity.
Screenshot for splash screen:
https://drive.google.com/file/d/17dC-REuko1zoQztUlUVcZQBkO4mEjhsK/view?usp=sharing
Screenshot for main activity:
https://drive.google.com/file/d/14GmY72IRl8_--PGfo2qr7abrcZj4zxbj/view?usp=sharing
The code is the following :
MainActivity.Jave:
package com.example.acer;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
public WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //remove App Title bar
setContentView(R.layout.activity_main);
webView=(WebView)findViewById(R.id.webView);
WebSettings webSettings=webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("http://alkhaleej-med.com/");
webView.setWebViewClient(new WebViewClient());
}
#Override
public void onBackPressed(){
if(webView.canGoBack()){
webView.goBack();
}else{
super.onBackPressed();
}
}
}
SplashScreen.jave:
package com.example.acer;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
public class SplashScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //remove App Title bar
setContentView(R.layout.activity_splash_screen);
Thread myThread = new Thread(){
#Override
public void run() {
try {
sleep(4000);
Intent intent = new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
myThread.start();
}
}
Activity_Main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
tools:context=".MainActivity">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</RelativeLayout>
Activity_splash_screen.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SplashScreen">
<ImageView
android:layout_width="250dp"
android:layout_height="250dp"
android:src="#drawable/splash_logo"
android:layout_centerInParent="true"/>
</RelativeLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.acer">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
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=".MainActivity"></activity>
</application>
</manifest>
Thank you.
Go To res-values-styles and change your base theme to NoActionBar
e.g.
<!-- 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>
You are half way there:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

Why Do see two toolbars when I created an app that has a navigation drawer?

I have created an app that has a navigation drawer, it works fine, but the only problem is that I see two toolbars. One in which there is Actionbartoggle button and other which is default. Now the tutorial I have seen has used a toolbar in the main content of drawer layout and obviously navigation contents are coming from menu.
Now the problem is I think we have to pass a toolbar reference in the constructor of Actionbardrawertoggle, and after I passed it properly it works fine, but I see two toolbars/actionbars. Basically my question is how do I get the toggle button on the main action bar and not get second tool bar created? I have tried using
<style name="MyTheme" parent="android:Theme.Material.Light.NoActionBar">
It helps me to hide the upper actionbar but I don't think it's the good way to do it. I am uploading my screenshot of output and code:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Page Content -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
</LinearLayout>
<!-- Navigation View -->
<android.support.design.widget.NavigationView
android:id="#+id/navigationView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemTextColor="#5DADE2"
app:menu="#menu/drawer_items"/>
</android.support.v4.widget.DrawerLayout>
Mainactivity:
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Toast;
import java.util.HashMap;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
SessionManager session;
private Toolbar mToolbar;
private DrawerLayout mDrawerLayout;
ActionBarDrawerToggle drawerToggle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_area);
setupToolbarMenu();
setupNavigationDrawerMenu();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.lg:
session.logoutUser();
return true;
default:
return super.onOptionsItemSelected(item);
}
} private void setupToolbarMenu() {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitle("Home Page");
}
private void setupNavigationDrawerMenu() {
NavigationView navigationView = (NavigationView) findViewById(R.id.navigationView);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setItemIconTintList(null);
drawerToggle = new ActionBarDrawerToggle(this,
mDrawerLayout,mToolbar,
R.string.drawer_open,
R.string.drawer_close);
mDrawerLayout.addDrawerListener(drawerToggle);
drawerToggle.syncState();
} #Override // Called when Any Navigation Item is Clicked
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
closeDrawer();
switch (menuItem.getItemId()) {
case R.id.home:
// Put your Item specific Code here
break;
case R.id.invoice:
Intent intent = new Intent(this,details.class);
startActivity(intent);
// Put your item specific Code here
break;
}
return true;
}
// Close the Drawer
private void closeDrawer() {
mDrawerLayout.closeDrawer(GravityCompat.START);
}
// Open the Drawer
private void showDrawer() {
mDrawerLayout.openDrawer(GravityCompat.START);
}
#Override
public void onBackPressed() {
if (mDrawerLayout.isDrawerOpen(GravityCompat.START))
closeDrawer();
else{
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Exit")
.setMessage("Are you sure?")
.setPositiveButton("yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
}).setNegativeButton("no", null).show();}
}
}
my styles.xml file:
<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>
</resources>
I know this might not be of some use, but here's my manifest file too:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<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=".details" />
<activity android:name=".Login"
android:label="Login"/>
<activity android:name=".MainActivity" />
<activity android:name=".recycler" />
<activity android:name=".RegisterActivity" />
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And here's the output I am getting:
Try to follow this example: https://developer.android.com/training/appbar/setting-up.html
There you will find this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
}
the thing you are missing is: setSupportActionBar(myToolbar);

Action Bar producing NullPointerException [duplicate]

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

Android layout can not display in device

My Android Studio version is 1.5.1
I have created an XML and it can show well in the AndroidStudio,
but when i run it in genymotion or my phone,it can not show the layout.
I am annoyed at this.I do not know what is wrong.
hope someone could help me.
code image
code:
SplashActivity
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class SplashActivity extends AppCompatActivity {
private Button mEnterButton;
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.enter_button:
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
break;
}
}
};
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
setContentView(R.layout.activity_splash);
mEnterButton = (Button) findViewById(R.id.enter_button);
mEnterButton.setOnClickListener(mOnClickListener);
}
}
MainActivity
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button_first).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,SplashActivity.class);
startActivity(intent);
}
});
}
}
avtivity_splash_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#color/splashBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/splash_tv_text"
android:textSize="28sp"
android:id="#+id/text_splash"
android:textColor="#color/white"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/splash_click_to_inter"
android:id="#+id/enter_button"/>
</LinearLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geekband.geekbandprojects">
<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" >
</activity>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Why you need a PersistableBundle ?
make your OnCreateMethod like:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//anything here
}
i'm considering that you haven't already set the SplashActivity as the startup activity.So add the following code(or change it) on Manifest:
<activity
android:name=".Splash"
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=".MainActivity"/>
And let us know your MainActivity code and of course your Manifest with the logcat.
I will updated my answer after that.
And of course, i think you should use onClick on Oncreate method.

Categories

Resources