How to add header to Activity in Android - android

How to add a header to an existing android activity? All the examples that I found with a search engine are showing how to add a header to the list view.

I don't know what you are looking for..might be this answer is useful to you.

You have to add a view the xml that you're using for your layout. So for example, say your Activity is using a linear layout. You'd do:
<LinearLayout android:orientation="vertical" ....>
<LinearLayout....>
<!---- Header Stuff Goes Here ---->
</LinearLayout>
<!--- Rest of the layout for your activity goes here ---->
</LinearLayout>

What you are looking for is a ActionBar, it is included on 3.0 api but if you want to use with backward compatibility you can use different libraries, my preferit is GreenDroid you can also see an example downloading the GreenDroid Catalog App from Market.
I hope this helped you :)

Related

Using Material Design Components in Android Studio

I'm building my first app with Android studio and I'd like to use Material Design components such as cards in it.
I think I know how to add these by writing code, but I was wondering, is it possible to add cardview, recycleview etc. in design tab's palette somehow?
Whenever I used Android Studio to create material design apps, I always created the card through xml. It is then displayed correctly in the design view. However the widgets on the left hand side of the design view are only simple images, which are part of the actual Android API (do not need any extra references like in your case). To add a card to your page use the following xml:
<android.support.v7.widget.CardView
android:id="#+id/cardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:elevation="100dp"
card_view:cardBackgroundColor="#color/cardview_initial_background"
card_view:cardCornerRadius="8dp"
android:layout_marginLeft="#dimen/margin_large"
android:layout_marginRight="#dimen/margin_large"
>
//add any widgets which you want inserted in the card here
</android.support.v7.widget.CardView>
Code has been taken from here.
Hope this helps :)

Show other view on slide up android

I am starting a new project in android.I have to make it like google maps.For example see the image below
The screen will be like this with 2 views.1st mark with red and other with yellow.
Now what i want is that when user drags view 2 from bottom to top it should be like this
How can i achieve this.Please do help me out as i new to andriod development
Thanks
Checkout AndroidSlidingUpPanel library, probably this is what you want to achieve.
There's a similar implementation in this library. Download the sample app here and see the
SlidingUpGridView
SlidingUpListView
SlidingUpRecyclerView
SlidingUpScrollView
SlidingUpWebView
options.
EDIT
Looks like AndroidSlidingUpPanel is a better solution.
EDIT 2
If you don't want to use that library, I suggest use the codes of that library. It's really not that much work.
Create a new package sliderlib or something in your project
Create two classes named ViewDragHelper.java and SlidingUpPanelLayout.java
Copy the contents of the two named classes here
Download these drawables to your drawable directory of your app
Add these values to your attrs.xml (create one if there isn't one)
And in your XML, use your new widget like this.
your_layout.xml
<your.app.package.sliderlib.SlidingUpPanelLayout>
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="#+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:panelHeight="68dp"
sothree:shadowHeight="4dp">
<!-- Your views to show in your Sliding Up Panel -->
</your.app.package.sliderlib.SlidingUpPanelLayout>
NOTE : The answer may not be exactly right. But it will be a start.

What is the name for this layout under Android?

I would like to know if this kind of layout is supported under Android and what is its name.
The description:
the application is revealed by default in a main view and a menu will appear when making a "swipe gesture" from the margins to the center of the screen; usually this layout has to offer some kind of callback or manage to stop the underlaying activity for the application so the user can use the menu without interfering with what he is doing with the application itself.
Thanks.
If you are looking for a sliding layout, here is an example:
you can call it with:
<com.slidingmenu.lib.SlidingMenu
xmlns:sliding="http://schemas.android.com/apk/res-auto"
android:id="#+id/slidingmenulayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
sliding:viewAbove="#layout/YOUR_ABOVE_VIEW"
sliding:viewBehind="#layout/YOUR_BEHIND_BEHIND"
sliding:touchModeAbove="margin|fullscreen"
sliding:touchModeBehind="margin|fullscreen"
sliding:behindOffset="#dimen/YOUR_OFFSET"
sliding:behindWidth="#dimen/YOUR_WIDTH"
sliding:behindScrollScale="#dimen/YOUR_SCALE"
sliding:shadowDrawable="#drawable/YOUR_SHADOW"
sliding:shadowWidth="#dimen/YOUR_SHADOW_WIDTH" />
There is no built in function like that, so you have to use third party libraries
There is no built in functionality for this behavior. You'll need to make it yourself.

Android EditContactActivity source

Android EditContactActivity contains the functionality when + button is pressed new field is added to listview and - button delete that extra field. I need this exact functionality, but I could not find it in Android source code.
How to extract this particular functionality? And if someone can tell me how to understand android source code.
If i remember correctly it's not a ListView at all actually, more like:
<LinearLayout>
<ScrollView>
<LinearLayout>
All the editors go here
</LinearLayout>
</ScrollView>
<LinearLayout>
Buttons and stuff goes here
</LinearLayout>
</LinearLayout>
Basically they're adding and removing items in a LinearLayout at the right position.
If you want to look into the specifics a (complete?) mirror of the Android repo is up at github - the contacts app, for instance, is here: https://github.com/android/platform_packages_apps_contacts

Can I create a statich part of view

I`m wondering about one thing. If I decide to have a part of my View same in every Intent. For example 2 buttons at the bottom of screen and for example I have 3 diffrent views, List, Detail and a third one :) Do I need to put the buttons on every xml schem for each view or can I create other xml and attach it in each activity with all listener etc.
If I can attach in activity how can I do that ?
Create a XML buttons.xml with the common elements
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ImageButton
android:id="#+id/myButton"
android:src="#drawable/ic_title_search"
android:onClick="myHandle" />
<ImageButton
android:id="#+id/myButton2"
android:src="#drawable/ic_title_search"
android:onClick="myHandle" />
</merge>
Include it in another xml:
<include layout="#layout/buttons"/>
where buttons is the name of the xml file to be included
You can use the <include /> tag in your XML files.
See Layout Tricks for an example.
Create a separate layout for your buttons then in the layout you wish to display them use the include tag.
This will allow you to reuse the same layout in multiple parent layouts.
The include works as stated above you could also consider using fragments
Fragments
You can use these in older versions of Android by including the compatibility library in your application. It's definitely more work than a simple include but if you need some reusable UI for more sophisticated features than simple buttons you might want to look at that as well
How to use compatibility API

Categories

Resources