Android: How to set different layout title and titlebar icon image - android

I have 5 layout views in Eclipse Android application. I want to show different layout title and title icon image(in top left corner) in all the Graphical Layouts, not programmatically.
Currently, it is showing the same app title in all the layouts and also app icon image in all the views.
<application android:name="singleton"
android:allowBackup="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
I tried Login activity title label as below, login_name is already added in string: But, this is not showing any title there.
<activity
android:name="com.example.myappandroid.LoginActivity"
android:label="#string/login_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Please advise, how to fix this thru Graphical layout?

Do you say u want your own customize icon and title at the action bar.If yes then i will mention what i did for this...
1.first i create a customize xml file
2.ActionBar actionBar=getActionBar();
actionBar.setCustomView(R.layout.action_bar);//use this to load your own action bar
actionBar.setDisplayShowCustomEnabled(true);

Well what i did recently in my project is..
<?xml version="1.0" encoding="utf-8"?>//first i created a xml file for the ui i need
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/TopBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#E6E7E9" >
<ImageButton
android:id="#+id/baricon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#null"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
ActionBar actionBar=getActionBar();// then i call this part in my activity
actionBar.setCustomView(R.layout.action_bar);
actionBar.setDisplayShowCustomEnabled(true);
enter code here

Related

Show bg image with progress-bar on splash screen

I am trying to show a BG Image and Progress-bar on splash screen.
Code for splash.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_height="match_parent" android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:background="#drawable/spalsh">
<ProgressBar
android:id="#+id/loading"
style="?android:progressBarStyleLarge"
android:layout_width="wrap_content"
android:indeterminateDrawable="#layout/progressbartemplate"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:layout_marginBottom="10dp" />
</FrameLayout>
Then on Style I have
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:background" >#layout/splash</item>
</style>
Then I applied this style to Activity in manifiestfile
<activity
android:name="com.test.SplashActivity" android:theme="#style/SplashTheme"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But when the app starts I can not see the image and progress-bar while same i can see on the design view.
Same code will work if i use Layer-List and remove the progressbar.
Can someone pls suggest me how can i show the bg image with progress-bar at bottom?
Thanks in advance
I think there is problem in size of splash image you have to resize it by follow blow steps
1- right click on res
2- right click on drawable
3- click on new
4- Batch Drawable importer
5- click on plus + chose splash
I hope it will help you
try this, I hope this may resolve your issue.
<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="#mipmap/ic_launcher"
tools:context="com.example.viral.myapplication.MainActivity">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:padding="12dp"/>
</RelativeLayout>

Actionbar replaced with Toolbar showing Logo at Top left with App name ... workaround

As mentioned in the title I am expecting my Android App to show Actionbar / Toolbar with Logo at its left, followed by App name in the form of Title.
I had to perform some workaround in each activity so as to omit the text designed as a label in Android manifest.
Below I am providing code snippets for quick reference -
activity_main.xml ... Toolbar tag -
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize">
<ImageView android:id="#+id/myLogo"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/logo"
android:padding="4dp"
android:adjustViewBounds="true"/>
<TextView android:id="#+id/myTitle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="My App name"/>
</android.support.v7.widget.Toolbar>
Android manifest - Application tag -
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="My App name"
android:supportsRtl="true"
android:theme="#style/AppTheme.NoActionBar">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Styles.xml - Handling no actionbar
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
onCreate of AppCompatActivity -
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("");
setContentView(R.layout.activity_main_horizontal);
Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
TextView titleText = (TextView) findViewById(R.id.myTitle);
titleText.setTextColor(Color.WHITE);
setSupportActionBar(toolbar);
}
Now, from onCreate, if I remove or comment - setTitle("");
then ... output toolbar starts with label picking from Android manifest, followed by Logo, then TextView text indicating App name.
If I blank the label from Android manifest then, App launcher generated in the mobile is with a blank name.
By putting line - setTitle(""); I see it as workaround. Is there any elegant way, where I can omit the label from Android manifest appearing into the toolbar?
you have to do this, so you can do ur custom title
getSupportActionBar().setDisplayShowTitleEnabled(false);
and then manually setText to your textView inside toolbar
if you insist to get the title from manifest, you can do this
ActivityInfo activityInfo = getPackageManager().getActivityInfo(
getComponentName(), PackageManager.GET_META_DATA);
String title = activityInfo.loadLabel(getPackageManager())
.toString();

How to enable Split Action Bar?

I want to create an android application which has 3 sliding tab panel and each of them will 5 button (save,new,delete,exit..).
What I want is exactly as follow:
I created sliding tab panel.And for 5 button, I added split action bar.But It works as normal split action bar.My AndroidManifest.xml is:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.belsoft.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:uiOptions="splitActionBarWhenNarrow"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Where is my wrong?
To implement splitActionBar:
Just add android:uiOptions="splitActionBarWhenNarrow" to your activity tag in theAndroidManifest.xml like this...
`<activity
android:name=".MainActivity"
android:uiOptions="splitActionBarWhenNarrow">`<br>
You can read more here and here
NOTE: It is available ONLY for handset devices with a screen width
of 400dp.
To create a custom bottom toolbar:
If you want to set it for all devices, please check my answer (find a post starting with Creating custom bottom toolbar) here:
Creating custom bottom toolbar
I've already created a simple app which should demonstrate you how to
begin
Creating a custom ViewGroup
Here's my activity_main.xml layout file:
<?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:padding="0dp"
tools:context="com.example.piotr.myapplication.MainActivity">
<LinearLayout
android:id="#+id/show_pdf"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#color/primary_material_light"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_cut_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_copy_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_paste_mtrl_am_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_share_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_selectall_mtrl_alpha"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/abc_ic_menu_moreoverflow_mtrl_alpha"/>
</LinearLayout>
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"/>
</RelativeLayout>
As you can see my parent ViewGroup is RelativeLayout, which simply
allows me to create a view at the bottom of screen.
Notice that I set layout padding to zero (I think: setting layout
margin to zero here is not necessary, the same effect). If you'd
change it, the toolbar won't use full width and it won't stick with
bottom of the screen.
Then I added a Linear Layout with hardcoded height which is:
android:layout_height="40dp"
I wanted it, that my bottom toolbar would take full available width so
I set it as match_parent.
Next, I added some ImageButton views with images from Android
library.
There you have two possibilities:
if you really want to have a toolbar like in above example just remove in every ImageButton view this line:
android:layout_weight="1"
After removing weights and some buttons you would get a view pretty
similar to expected:
if you want to take the full width and make every button with the same size use in your project weight as in this mine example.
Now let's go to my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.piotr.myapplication"
xmlns:android="http://schemas.android.com/apk/res/android">
<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"
android:windowSoftInputMode="stateVisible|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
In that file I'd added as you can see only one additional line:
android:windowSoftInputMode="stateVisible|adjustResize">
to make sure that device keyboard won't hide my custom bottom toolbar.
From: How to add a bottom menu to Android activity
If you have any question please free to ask.
Hope it help

How can I get a multiline custom title on android?

I am working on a xamarin project (has no relevance here as far as I can tell - the android layout properties are the same)
I am using Window.SetFeatureInt (WindowFeatures.CustomTitle, ...) to set the title (2 "columns". I wish to make two rows of text though for my title. Is this possible? I have not had much success. I have an upper left, upper right and lower left and lower right TextViews to set.
My previous attempts have ended up with the TextViews overwriting each other.
Here I am designing a XML file with an image, text for title & button. This is the XML file. U can use it however you want, for a complete application or perticular activity.
In case of activity add this activity's theme tag. For multi line just use text view in side the below linear layout, set it as multline true.
<?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:background="#android:color/darker_gray">
<ImageView
android:id="#+id/header"
android:background="#drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Custom Window Text"
android:textColor="#android:color/black"
android:textStyle="bold"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
Create a theme in Custom_theme.xml,
<resources>
<style name="CustomWindowTitleBarBG">
<item name="android:background">#323331</item>
</style>
<style name="TitleBarTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle"> #style/CustomWindowTitleBarBG</item>
</style>
Modify the AndroidManifest.xml file as follows for applying custom theme
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/TitleBarTheme" >
<activity
android:name=".CustomWindowTitle"
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>
Now in main java file add “requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)” &
“getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title)”
This is the code snippet for CustomWindowTitle.java
package com.example.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class CustomWindowTitle extends Activity
{
#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);
}
}

Android App to always stay in Landscape

I have looked Here but am still unable to tackle my problem.
I have recently jumped into android (headfirst) and have been messing around. I would like my application to only run in Landscape mode no matter which way the screen is tilted.
My home screen is basically a page with a background and a few buttons that are aligned on the right side.
Here is my XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft = "450px"
android:paddingRight = "60px"
android:paddingTop="25px"
//I have tried adding orientation commands here like the one below??
android:screenOrientation="landscape"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background = "#drawable/sign"
>
<Button
android:id="#+id/Button1"
android.layout_height="60px"
android.layout_width="30px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Button1"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="#+id/Button2"
android.layout_height="60px"
android.layout_width="30px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="Button2"/>
add this line in your manifest.xml file.
<activity android:name=".activity" android:screenOrientation="portrait"></activity>
if you want only landscape orientation then change landscape instead of portrait
see this How to set android show vertical orientation?
Add the following property all the activites in your manifest file:
android:screenOrientation="landscape"
for example:
<activity android:name=".MainActivity" android:screenOrientation="landscape" " >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
you can add this property in your application tag also in the manifest file .
hope this help you to solve your issue.
You need to put android:screenOrientation="landscape" on the activity tag in your AndroidManifest.xml file.
Reference: http://developer.android.com/guide/topics/manifest/activity-element.html

Categories

Resources