Make Custom Navigation drawer like You-Tube in android - android

Hello friends i wnat to make custom slidng drawer like you-tube in my application
When user click on any item it should be show me like above image which i highlight so any idea how can i achieve this ?

Yesterday I faced same problem
but this examples highlight selector in whole listbackground but i also want red color indicator at starting which is mention
You need to create two selector. 1. For whole item 2. for that red part
For that Place a view in listitem on left side and create a selector for it.
then use following code. Here android:duplicateParentState="true" works for you.
When this attribute is set to true, the view gets its drawable state
(focused, pressed, etc.) from its direct parent rather than from
itself.
<TextView
android:layout_width="3dp"
android:layout_height="match_parent"
android:duplicateParentState="true"
android:background="#drawable/selector_for_red" />

Related

Android Spinner - How to position dropdown arrow as close to text as possible when options have different length?

The options in my spinner has different length and currently the dropdown arrow is positioned far to the right based on the longest option, as shown in the screenshot below.
Is it possible to move the dropdown arrow so that it is dynamically positioned based on currently selected option?
Especially when the first option is just 'All', it looks weird when the dropdown arrow is so far away to the right.
Referring to Google Translate App where dropdown arrow is always positioned next to its text:
You cannot control the position of the original dropdown icon, the only way is to disable the default icon and add your own one into the dropdown.
First, disable the default dropdown icon by setting the background of the Spinner to #null:
<Spinner
android:id="#+id/spinner_main"
android:spinnerMode="dropdown"
android:background="#null"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
Then create a layout resource spinner_item_main.xml with only one TextView which we can set a drawable on its right side (you can download the arrow picture from here):
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="left"
android:textColor="#color/colorWhite"
android:drawableRight="#drawable/ic_arrow_drop_down_white_24dp"
/>
Finally Set this layout resource when you initialize the Spinner, You can also provide a resource as the dropdown view (as what I have done):
(I use kotlin)
spinner_main.adapter = ArrayAdapter<String>(this,
R.layout.spinner_item_main, objects).apply {
setDropDownViewResource(R.layout.spinner_dropdown_view_main)
}
Make it!
View this in My APP
Translating #尹小雨 answer to java
ArrayAdapter adapter = new ArrayAdapter<Category>(this,R.layout.spinner_item_main,objects); // creates new ArrayAdapter with custom textviews for all elements including the first one (which is what we want)
adapter.setDropDownViewResource(R.layout.spinner_dropdown_view_main); // Modifies all the elements when you click on the dropdown
spinner.setAdapter(adapter); // sets the adapter to the spinner

Android list items overlap listview borders

I am working with the simple ListView. Need to make this ListView round (not the every list item round, but the ListView itself). So for this purpose I use shape xml-file. It looks like that:
The problem appears when I need to change color of the items. This color overlaps border of the listview. And it looks something like that:
As you can see, the listView is square again, not rounded. How can I prevent this? Couldn't found the solution though it seems a pretty much common thing to me.
If you want to add space around you list item add in you list item layout..
android:paddingTop="2dp"
android:paddingRight="2dp"
android:paddingLeft="2dp";
android:paddingBottom="2dp";
or
android:padding="2dp"
Use padding in listview..
android:padding="5dp"

Creating header with home page(Landing screen) button

One of the application in my mobile has a header like the one shown below in the snapshot. I like the design very much and would like to create one for my application. Clicking the home icon takes the user to landing page(Home page). I have only created buttons of squarish and rounder corners. But not sure, how to create one like the one given below. Any help would be highly appreciated.
Create the image in photoshop or whatever.
Then create an imageview and let it act like a button:
<ImageView
android:id="#+id/camera_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/button_camera"
android:onClick="onCameraButtonClick" />
onClick is introduced in Android 1.6
or a button and set the background:
<Button
android:id="#+id/camera_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_camera"
android:onClick="onCameraButtonClick" />
drawable/camera_button should be a state drawable so the user can see when it is being clicked/focused.
in your activity:
public void onCameraButtonClick(View v){
// Do Something
}
It's all here:
http://developer.android.com/reference/android/widget/Button.html
The way that I would do this is just create the buttons in photoshop/GIMP on the same canvas then save each as PNG, you can use the slice tool for this. Then I would just add an attributes to each button. There's attributes that let you set the left margin of say the right button to line up with the right margin of the left button. The backgrounds of the buttons could also be patch9 images, and the icons inside it could be the src attribute of the button view. The button with the camera would have SRC pointing to a PNG that has the camera icon as well as "Camera". And the button itself not having any text.

Removing Android ToggleButton's green indicator light

I would like my app to have a day of week selector with multiple day selection capability. I'm using ToggleButtons for this right now, but because of the indicator lights a ToggleButton takes too much space on the screen. Without the lights, my ToggleButtons would look like normal (toggleable) Buttons and they could fit in one row. How can I hide the lights?
The answer is this part:
android:background="#android:drawable/btn_default"
For example, following will make the light disappear and toggle button would look like a default button, but with the toggle functionality:
<ToggleButton android:id="#+id/your_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textOn="On" android:textOff="Off"
android:background="#android:drawable/btn_default" />
You can use a custom android:background drawable for them, that will override the graphics including the indicator light. If you look at Android: using framework drawables in custom button selector, there's instructions for copying resources from the SDK to your own project. You presumably could copy the platform normal button drawable and use that as your background.

Android ListView style

I have a question about list views. I hope someone knows the solution, because I have been trying to solve this problem all weekend.
I have a custom list view in which every row have a custom .xml (item_row.xml) with a set color background for the row item.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="70dip"
android:orientation="vertical"
android:background="#drawable/list_bg">
The problem is that when I try to make a selector for the list. I want two things:
When the item is focused, the typical orange rectangle should appear over it,
and the same When the item is pressed.
I have proved with a selector and a custom style but all I get is or the selector doesn't appear or the selector covering the item so I can't see it.
If anyone could help me with finding the right code I would be very grateful.
Thanks
Add an attribute to your ListView tag.
android:listSelector="#drawable/list_bg"
Now you can create your own style for your background using the XML file as drawable. For more information, check out the API Demos app, drawables section.
There is a special parameter for listview selected backgronud, i.e. android:listSelector. Setting this parameter to the background resource will solve your problem.

Categories

Resources