I have a problem to implement this situation, Seen here that natively has let the entire layout as belowlayout below.
But I would like to do this, this rectangle Should be a single and clickable item
How to do this ?
If you need to display something over the main content aPopupWindow will be the best choice.
First, you need to create a custom theme that extends an existing action bar theme and set the android:windowActionBarOverlay property to true.
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
</resources>
And add the following in your layout:
android:paddingTop="?android:attr/actionBarSize"
Example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="?android:attr/actionBarSize"> // <==== add this one
...
</RelativeLayout>
Read more about this.
Related
Is there a way to disable the fade-in / fade-out animation for ToolBar elements?
I found a solution for the status bar:
getWindow().getEnterTransition().excludeTarget(android.R.id.statusBarBackground, true);
But I can not find a similar fix for the ToolBar. Everytime I load a new Activity, it causes an undesired flash.
Edit:
styles.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Status Bar Color -->
<item name="android:colorPrimaryDark" tools:targetApi="21">#color/primary_4</item>
</style>
<!-- Toolbar Style -->
<style name="toolbar">
<item name="android:textColorPrimary">#color/primary_0</item>
<item name="colorControlNormal">#color/primary_0</item>
<item name="colorControlHighlight">#color/primary_3</item>
</style>
</resources>
In activity_main.xml & activity_details.xml
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
app:theme="#style/toolbar"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/actionBarSize"
android:background="#color/primary_4" />
The Elevation animation duration value is R.integer.app_bar_elevation_anim_duration which by default is 150.
To avoid the animation, just put following into any xml under res/values and that's it:
<integer name="app_bar_elevation_anim_duration" tools:override="true">0</integer>
The documentation for excludeTarget() says:
public Transition excludeTarget (View target,
boolean exclude) :
Whether to add the given target to the list of targets to exclude from
this transition. The exclude parameter specifies whether the target
should be added to or removed from the excluded list.
Excluding targets is a general mechanism for allowing transitions to
run on a view hierarchy while skipping target views that should not be
part of the transition. For example, you may want to avoid animating
children of a specific ListView or Spinner. Views can be excluded
either by their id, or by their instance reference, or by the Class of
that view
This means that the way you excluded the status bar from the enter transition would also work for the toolbar.
I tried it and it's working.
secondActivity.xml:
...
<include
android:id="#+id/customToolbar"
layout="#layout/toolbar" />
...
SecondActivity.java (Inside onCreate()):
...
getWindow().getEnterTransition().excludeTarget(R.id.customToolbar, true);
...
I am using actionbar sherlock and it works very well. The only problem I have is to figure out how to set the background image for the area which is used by the activities. All I end up with is setting a background image for the actionbar itself.
Any suggestion highly appreciated
martin
The windowBackground attribute is perfect for this.
<style name="MyTheme" parent="Theme.Sherlock">
<item name="android:windowBackground">here!</item>
</style>
Just set the background for your main layout in your activity.
Eg. in your layout file:
<LinearLayout 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:orientation="vertical"
android:background="#drawable/myImage" >
just write following line of code in your onCreate().
getSupportActionBar().setIcon(R.drawable.your_image);
I have three buttons to change themes. On clicking each button my app theme must change dynamically. How to do it programmatically.
To set the theme dynamically at runtime, call setTheme() in your activity's onCreate() method, before calling setContentView(). To change the theme, you simply need to restart your activity.
Here is a nice tutorial on how dynamically apply themes.
and this one too.
Please Visit this link for it.
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:typeface="monospace"
android:text="#string/hello" />
<TextView
style="#style/CodeFont"
android:text="#string/hello" />
By defining an xml theme file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CodeFont" parent="#android:style/TextAppearance.Medium">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
</style>
</resources>
You can also apply styles to all activities of an application:
<application android:theme="#style/CustomTheme">
Or just one activity:
<activity android:theme="#android:style/Theme.Dialog">
Sorry but you can't change styles programmatically.
how to set the Style Attribute Programmatically in Android?
There are certainly other methods to achieve this desired behavior however. You could set onclick listeners for each button, and programmatically change text size, color, background etc of your various view elements
you can use a particular theme for a given xml file.
in graphical layout you can CHANGE the theme of the layout using editing config.
use onclick event to go to next layout and here your theme will be different from the first one.
Vimalatha, to change your background when you click a button just add this code to the onClick function of your button.
myLinearLayout.setBackgroundColor(Color.BLUE);
Assuming that myLinearLayout is your LinearLayout name...
i have a title bar one of my project and i want to use my all screen.I think that i can do be a general( means i want a something and i will call everywhere like a style tag or theme tag) i have no idea.What can i use for?
My title bar is here:
RelativeLayout
android:layout_height="44dip"
android:layout_width="320dip"
android:background="#drawable/merhaba_header_320_44dip">
<ImageView
android:layout_height="32dip"
android:layout_width="121dip"
android:background="#drawable/merhaba_logo_121_32dip"
android:layout_centerInParent="true">
</ImageView>
<ImageView
android:layout_height="30dip"
android:layout_width="64dip"
android:background="#drawable/merhaba_btn_nedir_64_30dip"
android:layout_margin="5dip"
android:layout_alignParentRight="true">
</ImageView>
</RelativeLayout>
Hi DuyguK are you asking for a way to have a title bar that you can apply as a theme or something to all the activities in your app?
If that's so, I would recommend you to do the following.
First define a style in your res/values/styles.xml
<resources>
<style name="MyTheme" parent="android:style/Theme.Light">
<item name="android:windowTitleSize">44dip</item>
//whatever item you want/need to edit for your custom title bar
</style>
</resources>
This allows you to have a theme that is applyable to your whole app. To do this you need to go to your AndroidManifest.xml file an inside the application tag add the following:
<application android:label="#string/app_name"
android:theme="#style/MyTheme">
The android:theme tells the app to use the theme named "MyTheme" that can be found in the res/values/styles.xml file in your project.
That way you can apply correctly your custom title bar to all your activities.
Hope this answers your question if not, please specify!
An additional recommendation is to take a look at the ActionBarCompat project that comes with the samples in Android SDKs. The Android Developers page shows the project:
http://developer.android.com/resources/samples/ActionBarCompat/index.html
It has the advantage of being compatible with pre-API11 devices, is applied as a theme to your app and it is being used by lots of apps available in the store.
If you have any questions/trouble with it please tell me.
create your own style which can ofcourse extend from existing from an existing theme.
change the windowNoTitle to true.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="noTitleBarStyle" parent="android:Theme.Black">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/darkGrey</item>
<item name="android:colorForeground">#ff3333</item>
</style></resources>
This is more "Why?" than "How?" question, since I know a simple workaround for the problem. But I'd like to know what logic is behind behavior I'm going to describe.
I've got a style declaraion and some ListViews. I want to change the way divider looks. I used following declaration:
<style name="Theme.MyApp.Dark" parent="#style/Theme.Sherlock">
<item name="android:dividerHeight">4px</item>
<item name="android:divider">#123456</item>
</style>
To my amusement, only the height of the divider was applied. I've tried specifying color with alpha value (#12345678) and gradient drawable, nothing works. ListViews are declared like this:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
So, as you can see there's nothing that could override style declaration. I can change the divider only when I specify it directly in ListView declaration:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list"
android:divider="#123456"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Using my newly-acquired skill of specifying colors depending on theme selected, I can work around this very easily - I will just have to declare android:divider with custom color attribute for every list.
But why I can't change android:divider in the style, just like the android:dividerHeight? Is there some reason for that? I couldn't find an explanation, bug report or something similar that would let me understand this behavior.
EDIT: The theme is applied globally, in the Manifest file:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:name="org.my.app" android:theme="#style/Theme.MyApp.Dark">
It can be set from a theme but with a little trick:
<style name="MyTheme" parent="AppTheme">
<item name="android:listViewStyle">#style/MyListViewStyle</item>
</style>
<style name="MyListViewStyle" parent="#android:style/Widget.ListView">
<item name="android:divider">#F00</item>
<item name="android:dividerHeight">1px</item>
</style>
Rgrds ;)
You have to mention the style in the Lisview like this
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list"
style = "#style/Theme.MyApp.Dark"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Otherwise this wont work..