Android: How to get rid of the header bar in App? - android

For some reasons when I launch the app in the splash activity and in the row activity, see images, there is a header bar with the name of the app "Baby Read".
I don't want the header there, how do I get rid of it?
Splash Activity
Row Activity
[![enter image description here][2]][2]
This is the 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:background="#drawable/babyreadappsplash"
>
</LinearLayout>
And this is the row layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="#+id/icon"
android:layout_width="90px"
android:layout_height="90px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:layout_marginBottom="10px"
android:layout_marginTop="10px"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:id="#+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#+id/label"
>
</TextView>
This is res/values/styles after adding the code suggested
[![enter image description here][3]][3]
And this is the manifest after adding the code suggested

Create a style for your splash Activity like this
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
</style>
after that set this style for your splash Activity in Manifest
<activity
android:name="activity name"
android:theme="#style/AppTheme.NoActionBar"
/>
Update
make your style like this
<style name="splashStyle" parent="Theme.AppCompat.Light.NoActionBar">
//add other attributes
</style>
if not work for you change the parent of your AppTheme to Theme.AppCompat.Light.ActionBar

You can use this in onCreate:
getSupportActionBar().hide();

No need to create anew theme (At least for this purpose)
Modify you app theme (Picture one)change parent="android:Theme.Holo.Light.DarkActionBar" for parent="android:Theme.Holo.NoActionBar"
On you manifest, in the application section (picture 2)add
android:theme="#style/AppTheme"
If by any change you are supporting APIs below 13 you can add
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
to your app theme rather than changing the parent.
As a side note I would advise moving from Holo themes to Appcompat or even Material, but that´s out of the scope of this question

Related

How to Centralize Title text for Custom Action Bar through Styles.XML

I just created a custom action bar from my styles.xml class that shows up just the way I want it. And I have activated it from the manifest file.
<style name="customStyle" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="actionBarStyle">#style/customActionBarStyle</item>
<item name="android:textColorPrimary">#color/titletextcolor</item>
</style>
<style name="customActionBarStyle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/custom</item>
</style>
However, I'm trying to find a way to CENTRALIZE the title text on the action bar from the styles.xml file. Please can anyone help with how to do that.
I tried using this: <item name="android:layout_gravity">center</item>. But it had no effect.
Most of the suggestions I've seen online requires creating a toolbar layout separately. But I've done that and Its not what I want because It requires way more code.
Thank you.
To have a centered title in ABS (if you want to have this in the default ActionBar, just remove the "support" in the method names), you could just do this:
In your Activity, in your onCreate() method:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.abs_layout);
abs_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="my Title"
android:textColor="#ffffff"
android:id="#+id/mytext"
android:textSize="18sp" />
</LinearLayout>
Now you should have an Actionbar with just a title. If you want to set a custom background, set it in the Layout above (but then don't forget to set android:layout_height="match_parent").
or with:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.yourimage));

How to style Android Spinner with Material light theme on a dark background?

I can't figure out how to style this spinner in a dark-background drawer with the v21 Material theme. I've tried various approaches involving custom styles and nothing seems to make a difference with the appearance of this spinner.
Here's how it looks in the app, running on Android 5.0.1. The spinner, here with the selected item "Code on the Beach 2015", is in a drawer with a dark background (#DD000000), but the rest of the app is a light theme. The arrow shows as black - almost impossible to see on the device. I'd like to make it have a white arrow.
Here's my styles.xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="app_theme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#E95624</item>
<item name="colorPrimaryDark">#BD4000</item>
<item name="colorAccent">#86d3c5</item>
<item name="windowActionBar">false</item>
</style>
</resources>
And here's the Main.axml file, the main layout for this activity, that contains the DrawerLayout and the Spinner:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
a:layout_width="match_parent"
a:layout_height="match_parent"
a:orientation="vertical">
<android.support.v7.widget.Toolbar
a:id="#+id/main_toolbar"
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:minHeight="?attr/actionBarSize"
a:background="?attr/colorPrimary"
a:elevation="2dp"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
<android.support.v4.widget.DrawerLayout
a:id="#+id/drawer_layout"
a:layout_width="match_parent"
a:layout_height="match_parent">
<FrameLayout
a:id="#+id/content_frame"
a:layout_width="match_parent"
a:layout_height="match_parent" />
<LinearLayout
a:id="#+id/left_drawer"
a:orientation="vertical"
a:layout_width="240dp"
a:layout_height="match_parent"
a:layout_gravity="start"
a:background="#DD000000">
<Spinner
a:id="#+id/event_spinner"
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:padding="4dp" />
<ListView
a:id="#+id/left_drawer_list"
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:choiceMode="singleChoice"
a:divider="#android:color/transparent"
a:dividerHeight="0dp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
And in case it is relevant, here is the code that sets the spinner's adapter (Xamarin C#):
var adapter = new ArrayAdapter<string>(SupportActionBar.ThemedContext, Resource.Layout.event_selector, events);
adapter.SetDropDownViewResource(global::Android.Resource.Layout.SimpleSpinnerDropDownItem);
_eventSelector.Adapter = adapter;
And here's my event_selector.axml (I changed textColor to #fff after taking screenshot, did not affect arrow color):
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8dp"
android:textSize="16sp"
android:textColor="#fff" />
What modifications to my .axml or styles.xml files do I need to make to give this spinner a white arrow? Thanks in advance!
The key is to set the backgroundTint attribute to the color you want.
<Spinner
a:id="#+id/event_spinner"
a:layout_width="match_parent"
a:layout_height="wrap_content"
a:padding="4dp"
a:backgroundTint="#FFFFFF"/>

Calling android dialog without it fading the background

I have this nice dialog view I set my UserInputDialog class to:
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/nameMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="What is your name Captain?"
>
</TextView>
<EditText
android:id="#+id/nameEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
>
</EditText>
<LinearLayout android:id="#+id/LinearLayout02" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<Button
android:id="#+id/okButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK">
</Button>
<Button android:id="#+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel">
</Button>
</LinearLayout>
</LinearLayout>
I want my dialog to show up but for the background to not fade out. Is this possible? Cause the view that calls this dialog has a neato background I would like to be shown as a backdrop to the dialog.
I found this online:
<style name="doNotDim" parent="#android:style/Theme.Dialog">
<item name="android:backgroundDimAmount">0</item>
</style >
but not sure how to apply that to my dialog? I have a class called public class UserInputDialog extends Dialog implements OnClickListener. It sets its content view to the layout described above.
I think I am doing this all right, just not sure how to add that style so I can NOT fade the background.
Secondary question: Can you get new looks on your dialog (by say having an image or icon display with your text there) by using Themes?
You can also remove the dim effect by code with the following:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Create a res/values/styles.xml file and add this to it.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.DoNotDim" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
And apply the theme to your activity.
<activity android:name=".SampleActivity" android:theme="#style/Theme.DoNotDim">
Create a custom style and place it in your values folder
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourCustomStyle" parent="android:Theme">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
To set a style to an individual dialog you can use
Dialog dialog = new Dialog(context, R.style.YourCustomStyle);
For displaying dialog like TrueCaller do this:
In styles.xml file.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="myBackgroundStyle" parent="android:Theme.Dialog">
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
In AndroidManifest.xml do this:
<activity android:name=".SampleActivity" android:theme="#style/myBackgroundStyle">

Custom title bar without padding (Android)

So I am using the techniques in this thread to use a custom background for my titlebar. Unfortunately the framework places my layout inside a FrameLayout (title_container) which has padding as seen below.
(source: ggpht.com)
Is there anyway to remove the grey borders? The frame layout is defined in com.android.internal.R.id.title_container, so accessing the frame by ID would be fragile.
I was struggling with this same issue and now I have the answer!
As you probably have seen several places, you need to create a themes.xml resource:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
Note it is not often mentioned in the sites talking about custom title bars you need to select this theme at the view, activity, or application level. I do it at the application level by adding android:theme property to the application:
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/MyTheme">
You also need a styles.xml to define that WindowTitleBackgroundStyle. Unlike the various versions of this file I have seen floating aroung the web, I have added one additional line to the file that sets the padding to 0 which gets rid of the padding you are complaining about:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="WindowTitleBackground">
<item name="android:background">#android:color/transparent</item>
<item name="android:padding">0px</item>
</style>
</resources>
There is actually no need to use a custom layout to customise the background image. The following code in theme.xml will work:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TitlebarBackgroundStyle">
<item name="android:background">#drawable/header_bg</item>
</style>
<style name="Theme.OTPMain" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/TitlebarBackgroundStyle</item>
</style>
</resources>
However, if you do actually want to use a custom title bar, then the following code will remove the margin:
ViewGroup v = (ViewGroup) findViewById(android.R.id.title);
v.setPadding(0, 0, 0, 0)
title_bar_background was set as the ID of the background image in the XML. I set android:scaleType="fitXY".
There is a lenghty thread over on anddev.org that may be able to help you out
http://www.anddev.org/my_own_titlebar_backbutton_like_on_the_iphone-t4591.html
I have followed it and successfully created my own title bar which allows me to set the padding.
Xml for my title bar:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/header"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="38px" android:layout_width="fill_parent"
android:background="#drawable/gradient">
<TextView android:id="#+id/title" android:layout_width="wrap_content"
android:gravity="center_vertical" style="#style/PhoneText"
android:layout_alignParentLeft="true"
android:text="New Title" android:background="#android:color/transparent"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:padding="5dip" android:layout_marginBottom="7px"/>
<TextView android:id="#+id/time" android:layout_width="wrap_content"
android:gravity="center_vertical" style="#style/PhoneText2"
android:layout_alignParentRight="true"
android:text="Test Text" android:background="#android:color/transparent"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:padding="4dip" android:layout_marginBottom="7px"/>
</RelativeLayout>
The above creates a small gray bar with text aligned to the right and left sides
I got rid of the padding by getting the title container and setting the padding to 0. It works on Android 4.
titleContainerId = (Integer)Class.forName("com.android.internal.R$id").getField("title_container").get(null);
ViewGroup vg = ((ViewGroup) getWindow().findViewById(titleContainerId));
vg.setPadding(0, 0, 0, 0);
As mentioned by dalewking, you can change the Manifest like this:
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/MyTheme">
But it did not work for me until I added
android:theme="#style/MyTheme"
to the activity it self like:
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/CustomTheme" >
</activity>
As of 4.2 and ADT 21 when creating a default layout standard dimensions are added to the parent container:
<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=".MainActivity" >
</RelativeLayout>
Values are located in res/dimens.xml:
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
</resources>
Either remove them from the parent or change the dimens.xml values to your desired values.
I added the following padding item the AppTheme in styles.xml
<style name="AppTheme" parent="AppBaseTheme">
...
<item name="android:padding">0dp</item>
...
</style>
The Application manifest uses that theme:
<application
...
android:theme="#style/AppTheme" >
...
This resolved it for me.

Android - Activity that does not fill the parent screen

Any idea why this doesn't create an activity that looks like a popup instead of an activity that completely fills the screen?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="300dip"
android:layout_height="120dip"
android:layout_marginTop="100dip">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="120dip"
android:layout_width="300dip">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</RelativeLayout>
</LinearLayout>
I assumed that I only needed to set the layout height and layout width to something other than "fill_parent", but it still shows up as a black screen that completely fills the screen.
Ultimately, I simply want to create a popup, but I do not want to use an AlertDialog. Is this possible?
You must set your Activity's window to be floating. You can do this either by giving your activity the Dialog style defined by Android (android:style/Theme.Dialog), or define your own style, like this:
<style name="MyFloatingWindow">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Then set the style on your activity in the application's Manifest.
On my phone but check this website here it shows how to use PopupWindow correctly.
Hope this helps or points you in the right direction.

Categories

Resources