I am new to Android development. I am trying to develop a SMS app for Android. I am successful with reading the inbox and contacts and display them in a ListView item. Now, what I want to achieve is to have a ripple effect on these ListView items every-time they are clicked or touched or selected. I used listSelector but seems it's not working. If anybody could help me, below is my code:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<ListView
android:id="#+id/msglist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true"
android:listSelector="#777777" />
You are going to inflate a layout in your Adapter for ListView, right? Then you can go to that layout.xml and set android:background="?android:selectableItemBackground" to the root element.
NOTICE: Ripple effect can only happen above API 21(Lollipop) by doing this. Under Lollipop, when you touch the item, a transparent blue layer will appear and overlay your source content, which is shown as selecting state.
Related
The following layout xml snippet works fine. But if I make any attempt to remove the Floating Action Button in it, the background color of "#color/green" in main Layout element gets ignored by the IDEA/Android Studio Layout Editor.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="RtlHardcoded"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/green"
android:fitsSystemWindows="true">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:onClick="callDirector"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
android:src="#android:drawable/ic_dialog_alert"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#color/green"
tools:context="org.drachenschloss.bidzclient.MainActivity">
I'm perfectly content to remove both the FAB AND the CoordinatorLayout (if memory serves, I only put in the CoordinatorLayout for the FAB), thus moving all of the xmlns elements to the RelativeLayout as that would become the root layout element for the activity but that doesn't help either.
Again the green background color works fine in the app. It's just not shown in the IDE layout editor display. I've even tried adding
tools:background="#color/green"
in order to cause the root layout element (whichever it is) to make the layout display in IDEA get the clue, but nothing changes. The moment the FAB goes away, the background color for the activity does too.
Seems this is a difficult to reproduce issue in both IJ and Android Studio.
https://issuetracker.google.com/issues/62334380
I create a Navigation Drawer activity in Android. When the user clicks on the menu items, each menu item opens up a fragment.
Each fragment is set to:
fragment.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
tools:context="com.go.tutorial.Fragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hello fragment"
android:textSize="30sp"/>
</LinearLayout>
content_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.go.tutorial.MainActivity"
tools:showIn="#layout/app_bar_main"
android:id="#+id/relative_layout_for_fragment"
android:background="#color/fragmentBackground">
</RelativeLayout>
However, the fragments expand to fit their contents instead of maximizing or becoming "fullscreen"?
This results in a shadow that borders the fragment and makes the design look ugly.
Is there any way to fix or work around this?
I don't want it to become true "fullscreen" per se. But, I would like to maximize to the space of its parent activity.
I'm sure a lot of people would like fragments that automatically maximize to the full width and height of its parent activity right?
A feature like this should be built in since it seems like many would use it?
Replace you LinearLayout with FrameLayout , and make your fragment layout match parent .
I'm quite new to Android Studio and for my app I need to create a custom ListView made of cells that have:
2x textView
a non modifiable ratingView (Stars)
an imageView
the cells should look something like this:
I would really appreciate if you show me a way to do it using the design interface in Android Studio instead of the xml editor.
Up until now I created a simple listView but I don't know how to customize it. This is the xml code:
<?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: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="dancam.com.chords.TabMainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Hopefully you can understand and develop your design now.
you need to add the views for every line.
Add a row.xml in your layout resources.
Create a custom adapter for listview, in getView inflate row.xml.
Here is an example.
If you need a more flexible implementation, considere
using RecyclerView, guide here.
Hope it helps
I'm thinking of making an app's first view like this: it's just a basic search view with one EditText and two Button on it. I want the background image zooming in and out when user stay on this view, typing or doing nothing.
So I add zoomin.xml and set the animation to the view. Zooming is working but only problem is that it's zooming everything. I know it's because I set background image in the root element of the xml, but I don't know how to make it ONLY zoom in the background picture without affecting other views.
Here's my background image code in root element.
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#drawable/bcg2"
android:orientation="vertical"
android:gravity="center">
So I'm thinking if any floating view will do this? But I don't know how to do it. Or any other suggestion?
Thanks!
Use a fullscrean ImageView instead of the background attribute of the Linearlayout and zoom only the image
<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">
<ImageView
android:id="#+id/image_to_zoom"
android:src="#drawable/bcg2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center"/>
</RelativeLayout>
So I've run into a pretty peculiar issue here. I am using a navigation drawer that has the framelayout to switch out content. I current have two fragments built, one is just fine and the only thing it has in it is a button, no layout specified. My second fragment though has a relative layout with a textview and a listview.
When I load the listview (which uses the textview) I get this:
As you can see, the listview is greyed out. I have no immediate colors set in my layout for this so it's not all grey text, and I can still click each item and scroll the list. I have no idea what is causing this, any tips?
EDIT Here are snippets of my code where I am working with the layout:
View rootView = inflater.inflate(R.layout.fragment_read_it, container,
false);
And here is my layout:
<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" >
<TextView
android:id="#+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
And lastly my adapt and list:
ArrayAdapter<PressRelease> adapter = new ArrayAdapter<PressRelease>(
getActivity().getApplicationContext(),
android.R.layout.simple_list_item_1, pressReleases);
listView.setAdapter(adapter);
Please give specific color to textview like
<TextView
android:width="match_parent"
android:height="wrap_content"
android:textColor="#000000"
>
And in list view put cache color hint as transparent like
<ListView
android:width="match_parent"
android:height="wrap_content"
android:cacheColorHint="#andorid:color/transparent"
>
I found a solution in another thread.
Use android.R.layout.simple_list_item_1 with a light theme
I was using getApplicationContext() with my adapter, and for some reason using this with the light theme makes the colors on the listview light.