App header not explicitly defined but present - android

The app I'm working on has a predefined header that is not present in the layout.
layout/activity_wallpaper.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#id/screen_main"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include layout="#layout/loading_indicator"/>
</LinearLayout>
which renders as:
"App title" is present in:
xml/wallpaper.xml:
<?xml version="1.0" encoding="utf-8"?>
<wallpaper
xmlns:android="http://schemas.android.com/apk/res/android"
android:label="#string/app_name"
android:settingsActivity="com.dayafternight.wallpaper.SettingsActivity"
android:thumbnail="#drawable/app_icon">
</wallpaper>
The layout is loaded in an activity:
#Override
#SuppressWarnings("deprecation")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wallpaper);
but it doesn't explicitly refer the title. Where is the title inserted in the layout?
Grepping for the title gives an entry in strings.xml:
<string name="app_name">App title</string>
and AndroidManifest.xml:
<application android:icon="#drawable/app_icon" android:label="#string/app_name" android:isGame="false" android:banner="#drawable/app_banner">
How can I discard the application name as part of my activity's layout?

We could do it in couple ways:
By setting ActionBar not to show title.
getSupportActionBar().setDisplayShowTitleEnabled(false);
After setContentView(..); call.
By theme.
<style name="AppTheme.NoTitleActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And apply this theme to the activity in the AndroidManifest.xml file:
android:theme="#style/AppTheme.NoTitleActionBar">
By setting empty title to the toolbar if we are using one.
<ToolBar
...
app:title=""
../>

Related

Material Drawer In Eclipse Isse

i want to add material drawer in android app ...so we need we have to include a toolbar ..
but when we include toolbar i got error
my Code for activitymain_xml is
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_parent_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true">
<include layout="#layout/toolbar"/>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#004869"
android:textSize="20sp"
android:dividerHeight="1dp"
android:background="#fff"
android:textColor="#f9f5f5"
android:paddingLeft="15sp"
android:paddingRight="15sp"
android:paddingTop="10dp"
/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
code for toolbar is
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
app:theme="#style/ThemeOverlay.AppCompat.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="#drawable/toolbar_background"/>
code for include toolbar is
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
My Style.xml is
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
My Mainifiest file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.lifegoal.eshop"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="13"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.lifegoal.eshop.Splash_Screen_Activity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</manifest>
But I got error like
04-28 12:53:05.632: E/AndroidRuntime(3181): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lifegoal.eshop/com.lifegoal.eshop.Home_Screen_Activity}: 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.
04-28 12:53:05.632: E/AndroidRuntime(3181): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
04-28 12:53:05.632: E/AndroidRuntime(3181): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
Guys I Need ur help ..thx in advance
Try changing your style.xml like below It works for me:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
According to developers guide we have to use NoActionBar theme to use toolbar as a action bar.
Also extends your activity with ActionBarActivity.
Edit
Use AppCompatActivity instead of ActionBarActivity, It is deprecated.
Try to do following :-
Remove this line from your toolbar.xml:-
android:id="#+id/toolbar"
And add this line in your activitymain_xml file:-
android:id="#+id/toolbar"
And extend parent theme Theme.AppCompat.Light.NoActionBar
AppCompat does not support the current theme features
Seems like, your style of Theme is wrong.
Your style.xml should contain these lines:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
P.S. : Your Theme should extend Theme.AppCompat.Light.NoActionBar instead of Theme.AppCompat.Light

Android: Theme changing more than it should

I need to change my app title background color. I were able to do that based on this question. But this is not only changing my title, but my whole app as well (edittexts, buttons, spinners).
Can I use something like this to change only the title, but keep everything else as the default theme?
I'm using Theme.Black, by the way.
Here follows some code I'm using:
res/values.themes.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="android:Theme.Black">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
res/values/styles.xml:
<resources>
<style name="AppTheme" parent="android:Theme.Black" />
<style name="WindowTitleBackground" parent="android:Theme.Black">
<item name="android:background">#color/titlebackgroundcolor</item>
</style>
</resources>
res/layout/mytitle.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myTitle"
android:text="This is my new title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#color/titletextcolor"
/>
</RelativeLayout>
And in my activity I call:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_auth);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);
}
and in AndroidManifest:
<application
android:icon="#drawable/ic_launcher_"
android:label="#string/app_name"
android:theme="#style/customTheme" >
Thanks in advance.

How to show my app name in two line in android in QVGA

I used my app name as Seecycle Free in a string. XML file and retrieve it in the Android manifest file. It appears fine in all devices but in QVGA device its appear in one line.
Why this happen, is there any solution by which my app name appears in two-line in QVGA device also, just as it appears in other devices.
create custom title instead of using default title:
for that u need to create an xml file in layouts similar to this:
You can also add images here:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myTitle"
android:text="This is my new title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#color/titletextcolor"
android:gravity="center_horizontal"
android:textStyle="bold"
android:typeface="serif"
/>
In java u need to add:
//beforesetcontentView
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//after setcontentview
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mytitle);
TextView txt = (TextView) findViewById(R.id.myTitle);
txt.setText("ur title");
In manifest file:
<activity android:name=".MyActivity" android:theme="#style/customTheme" />
create a file themes.xml in res/values:
<?xml version="1.0" encoding="utf-8"?>
<resources><style name="customTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
finally create styles.xml in res/values:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="WindowTitleBackground">
<item name="android:background">#ff0000</item>
</style>
</resources>

Android splash screen, opaque background not working

I'm trying to get the background of my splash screen to be opaque/transparent. I made a colors.xml in values:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="translucent_black">#00000000</color>
</resources>
Then I have my splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#color/translucent_black">
<ImageView android:layout_width="wrap_content" android:id="#+id/imageView1"
android:src="#drawable/splash" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"></ImageView>
</RelativeLayout>
I feel like I should have something in the manifest, but I keep getting errors putting activitys in. Also if you are really feeling frisky, I can figure out how to make the title bar go away either. Thanks again.
Simple Method
Specify the activity to use the translucent theme (in manifest.xml):
<activity ...
android:theme="#android:style/Theme.Translucent"
.../>
Advanced Method
If you want more customisability you can create your own theme extending the Translucent theme (manifest.xml):
<activity ...
android:theme="#android:style/Theme.MyTranslucentTheme"
.../>
and in styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTranslucentTheme" parent="android:Theme.Translucent">
<item name="android:windowBackground">#color/transparent_black</item>
</style>
<color name="transparent_black">#DA000000</color>
</resources>
If you use
<
activity
...
android:theme="#android:style/Theme.Translucent"
....../>
you have to extend Activity instead of AppCompatActivity in Activity.class inheritance.

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.

Categories

Resources