How to hide Title Android - android

i am trying to make a mini-game program and i cant get the title bar to go away i have already tried the following getActionBar().hide(); , requestWindowFeature(Window.FEATURE_NO_TITLE); here is what i have so far.
package com.example.marcus.game;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_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"
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:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
tools:context="com.example.marcus.game.MainActivity"
android:background="#752fdf">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
android:layout_centerHorizontal="true" />
</RelativeLayout>

Add this style to your styles.xml:
<style name="AppTheme.Fullscreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
You can also add :
<item name="android:windowTranslucentStatus">true</item>
to your v21 style.
Change your androidmanifest.xml to use the style:
<activity
android:name="MainActivity"
android:theme="#style/AppTheme.Fullscreen"/>

see About the Full Screen And No Titlebar from manifest
add
android:theme="#android:style/Theme.NoTitleBar"
to your activity or application in the manifest
and change
"extends AppCompatActivity"
to
"extends Activity"

Related

Scene transition image drawn in tiles during transition

I'm facing weird drawing issue with scene transitions (running with Nexus 5x 6.0.1 platform)
I found out that <item name="android:windowBackground">#null</item> has some relation to the issue.
Anyone know why this happens and what can be possible places to check in order to fix this?
Here is my test project setup to reproduce the problem:
minSdkVersion 16 and targetSdkVersion 23 using:
com.android.support:appcompat-v7:23.3.0
AndroidManifest.xml
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".NextActivity"/>
</application>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#null</item>
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View iv = findViewById(R.id.iv_test);
ViewCompat.setTransitionName(iv, "test");
findViewById(R.id.b_go).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this,
android.support.v4.util.Pair.create(iv, "test")).toBundle();
startActivity(new Intent(MainActivity.this, NextActivity.class), bundle);
}
});
}
}
NextActivity.java
public class NextActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_next);
final View iv = findViewById(R.id.iv_test);
ViewCompat.setTransitionName(iv, "test");
}
}
activity_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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
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.test.scenetransitions.MainActivity">
<ImageView
android:id="#+id/iv_test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_dialog_email"
android:tint="#color/colorAccent"/>
<Button
android:id="#+id/b_go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#color/colorAccent"
android:padding="20dp"
android:text="GO"/>
</RelativeLayout>
activity_next.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"
android:background="#android:color/white"
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.test.scenetransitions.MainActivity">
<ImageView
android:id="#+id/iv_test"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:src="#android:drawable/ic_dialog_email"
android:tint="#color/colorAccent"/>
</RelativeLayout>
And here is screenshot took in proper time during the transition:
The issue is with <item name="android:windowBackground">#null</item> you should never ever use null for window background. Replace it with <item name="android:windowBackground">#android:color/transparent</item>
When you set it to null Android doesn't know what to draw and it could draw any garbage from GPU. So you should explicitly specify transparent background.
I copy pasted your code, but i didn't get any drawing issues. I mean when the second page opens up, the image is a bit blurry(pixelated) that's cause of the small size of the actual image(if that's the case just use a bigger image in the second activity). May be its your device. I tested this in Moto E2. For me the transition is smooth, no drawing issues what so ever.

how to delete the toolbar in android design

The red frame should not have in my code, but after I updated my Android Studio, it is showed in all of my APPS. please click and see the picture.
How to delete the red frame from my code? And it could not find in its design/text. The blue frame's begin code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/activity_login_user_email_edt"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingLeft="35dp"
android:autoText="true"
android:hint="e-mail" />
The Answer Skynet posted is correct,but this is the programatical way
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Full Screen and remove toolbar
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
That is the theme your activity is extending from. You change it in the styles.xml. Then you need to update this setting in the Manifest.
You need to add this to styles.xml:
<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>
Then in your AndroidManifest.xml for this Activity:
<activity
android:name=".YourActivity"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen">
</activity>
The above will work if you are extending from AppCompatActivity which should look like:
public class YourActivity extends AppCompatActivity{}

Toolbar and ActionBar not shown in activity

I use Material design firstly in my apps and my problem is when I create activity there is no action bar or toolbar but I have Material Navigation drawer why it not implemented automatically like in older versions
Layout of activity:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView4" />
</LinearLayout>
Activity:
package fragments;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
public class Noname1 extends ActionBarActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
}
`
My theme:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/nliveo_green_colorPrimary</item>
<item name="colorPrimaryDark">#color/nliveo_green_colorPrimaryDark</item>
<item name="colorAccent">#color/nliveo_green_colorPrimary</item>
<item name="android:textColorPrimary">#color/myTextPrimaryColor</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:windowBackground">#color/myWindowBackground</item>
</style>
Make a custom_toolbar.xml file like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#color/nliveo_green_colorPrimary"
android:layout_height="?android:attr/actionBarSize" />
Include it in your layout file wherever you want like:
<include android:id="#+id/toolBar" layout="#layout/custom_toolbar"/>
in Your onCreate Method:
public class Noname1 extends ActionBarActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Toolbar tb = (Toolbar)findViewById(R.id.toolBar);
setSupportActionBar(tb);
}
}
And keep your manifest file:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/nliveo_green_colorPrimary</item>
<item name="colorPrimaryDark">#color/nliveo_green_colorPrimaryDark</item>
<item name="colorAccent">#color/nliveo_green_colorPrimary</item>
<item name="android:textColorPrimary">#color/myTextPrimaryColor</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:windowBackground">#color/myWindowBackground</item>
</style>
Hope it helps!!!
You should include toolbar in your layout. Something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
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:background="?attr/colorPrimaryDark"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView4" />
</LinearLayout>
Hope it helps you!!
Write getSupportActionBar().setDisplayHomeAsUpEnabled(true); if you are using support library and if not then remove Support just write getActionBar().setDisplayHomeAsUpEnabled(true);

Title bar not showing an Image

I have written a code for showing Image and Text in title bar. Text is showing, but not the Image.
Here is layout_my_title.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_launcher"
android:padding="5dp"
android:text="#string/bv_title_string"
android:textColor="#color/White"
android:textSize="20sp" />
Here is styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="customTitleBackground">
<item name="android:background">#color/titlebackgroundcolor</item>
</style>
</resources>
Here is themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="customTheme" parent="android:Theme">
<item name="android:windowTitleSize">45dp</item>
<item name="android:windowTitleBackgroundStyle">#style/customTitleBackground</item>
</style>
Create custom layout for window title in “layout” folder.
window_title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="35dip"
android:gravity="center_vertical"
android:paddingLeft="5dip"
android:background="#323331">
<ImageView
android:id="#+id/header"
android:src="#drawable/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Create custom style in “values” folder.
custom_style.xml
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
Apply custom style in manifest file as theme.
AndroidManifest.xml
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/CustomTheme">
Apply custom window title in main activity class
CustomWindowTitle.xml
public class CustomWindowTitle extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
} }
i hope this will help you out.

Custom title bar issue

I set a custom title bar as example http://coderzheaven.com/2011/06/custom-title-bar-in-android/ , every thing works fine but still blue frame appear from original title . The only thing I added is to set the background color to custom title as (android:background="#EECBAD"). How can I remove this blue frame?
###custom_title.xml:
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EECBAD"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="40dip"
android:id="#+id/ImageView01"
android:background="#drawable/ic_launcher"
android:layout_height="40dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv"
android:text="ELNABIH"
android:layout_toRightOf="#+id/ImageView01"
android:textColor="#drawable/red"
android:textStyle="bold"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" />
</RelativeLayout>
java.class
package com.test.list;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;
public class Tttt extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Boolean customTitleSupported = requestWindowFeature
(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
if (customTitleSupported) {
getWindow().setFeatureInt
(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText("name");
}
}
}
Brother, I think this link would help you for sure. I think you'll have to define styles and themes in xml too.
Please create styles.xml & themes.xml in values folder folder under res. Write the following code :
Code for styles.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources> <style name="WindowTitleBackground" parent="android:Theme">
<item name="android:background">#android:color/background_dark</item>
</style>
</resources>
Code for themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">54px</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
and insert this in your manifest - android:theme="#style/MyTheme"
Try to override "android:windowTitleBackgroundStyle".
If you set the background color for tv TextView, it's because it also has some right and left padding, beside being set to wrap_content:
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
You can remove those lines, or try to set the background color for the parent, RelativeLayout01
put on style.xml:
<style name="CustomWindowTitleBackground">
<item name="android:background">#color/LightFacebook</item>
</style>
on #color/LightFacebook use u custom color.
You should hide the default title first. You should declare that in AndroidManifest.xml for the activity or set the window params in the java code.
<activity
android:name=".MainActivity"
android:theme="#android:style/Theme.Black.NoTitleBar" />

Categories

Resources