The problem I have is that I have a white screen displayed when I want to switch between the 1st activity "ww1" and the 2nd activity "ww2", I have already tried a solution which says that I should create a theme in my styles.xml and add it to my second activity but the result was a black screen displayed while switching between the activity .
Here's the ww1.xml :
<?xml version="1.0" encoding="utf-8"?>
<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:background="#drawable/ww1"
tools:context=".ww1">
<Button
android:id="#+id/menu"
android:layout_width="163dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/menu"
android:visibility="visible" />
<Button
android:id="#+id/next_btn"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="210dp"
android:background="#drawable/next"
android:visibility="visible" />
ww2.XML :
<?xml version="1.0" encoding="utf-8"?>
<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:background="#drawable/ww2"
tools:context=".ww2">
<Button
android:id="#+id/menu"
android:layout_width="163dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/menu"
android:visibility="visible" />
<Button
android:id="#+id/next_btn"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/previous_btn"
android:background="#drawable/next"
android:visibility="visible" />
<Button
android:id="#+id/previous_btn"
android:layout_width="57dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="211dp"
android:background="#drawable/previous"
android:visibility="visible" />
Code used to display the ww2.xml :
Intent mySuperIntent = new Intent(ww1.this, ww2.class);
startActivity(mySuperIntent);
overridePendingTransition(R.anim.slide_from_right,R.anim.slide_to_left);
Use it its worked for me
Intent mySuperIntent = new Intent(ww1.this, ww2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mySuperIntent);
overridePendingTransition(R.anim.slide_from_right,R.anim.slide_to_left);
if dont work use it
in Your style add
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:windowDisablePreview">true</item>
</style>
However a better approach is do less things on main thread during Activity.onCreate and let show the preview screen while user is waiting. For a smooth transition, you can set a custom background to your windows adding this to your theme:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:windowBackground">#drawable/slash_screen</item>
</style>
Related
I tried to change the style, but apart from the round corners nothing worked.Here example of bottom sheet https://i.stack.imgur.com/6O92g.jpg.
Can anyone helps? Here what I tried and I got shadow line after I opened modal https://i.stack.imgur.com/uoHNA.jpg
I am trying to create custom modal bottom sheet with line on the top, how can I achieve that?
MainAct
class MainActivity : AppCompatActivity() {
lateinit var btnShowBottomSheet: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btnShowBottomSheet = findViewById(R.id.idBtnShowBottomSheet);
btnShowBottomSheet.setOnClickListener {
val dialog = BottomSheetDialog(this)
val view = layoutInflater.inflate(R.layout.bottom_sheet_dialog, null)
val btnClose = view.findViewById<Button>(R.id.idBtnDismiss)
btnClose.setOnClickListener {
dialog.dismiss()
}
dialog.setContentView(view)
dialog.show()
}
}
}
Bottom_sheet_xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rounded_top_corners"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="20dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_rectangle"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
>
<!--image view for displaying course image-->
<ImageView
android:id="#+id/idIVCourse"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:src="#drawable/ic_launcher_background" />
<!--text view for displaying course name-->
<TextView
android:id="#+id/idTVCourseName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_toEndOf="#id/idIVCourse"
android:layout_toRightOf="#id/idIVCourse"
android:text="DSA Self Paced Course"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<!--text view for displaying course tracks-->
<TextView
android:id="#+id/idTVCourseTracks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/idTVCourseName"
android:layout_marginTop="10dp"
android:layout_toEndOf="#id/idIVCourse"
android:layout_toRightOf="#id/idIVCourse"
android:text="Course Tracks : 30"
android:textColor="#color/black"
android:textSize="15sp" />
<!--text view for displaying course duration-->
<TextView
android:id="#+id/idTVCourseDuration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/idTVCourseTracks"
android:layout_marginTop="10dp"
android:layout_toEndOf="#id/idIVCourse"
android:layout_toRightOf="#id/idIVCourse"
android:text="Course Duration : 4 Months"
android:textColor="#color/black"
android:textSize="15sp" />
<!--button for dismissing our dialog-->
<Button
android:id="#+id/idBtnDismiss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/idIVCourse"
android:layout_margin="10dp"
android:text="Dismiss dialog"
android:textAllCaps="false" />
</RelativeLayout>
</RelativeLayout>
Based on the xml and code you have posted you have to make the below changes:
1.Change the xml android:background structure to be like below. The drawable which has rounded corners must be set to the 2nd child of RelativeLayout instead of parent and all other RelativeLayouts must have android:background="#android:color/transparent":
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#android:color/transparent">
<ImageView
android:layout_width="80dp"
android:layout_height="10dp"
android:background="#color/white"
android:layout_centerInParent="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="#drawable/rounded_top_corners">
<!--image view for displaying course image-->
<ImageView
android:id="#+id/idIVCourse"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:src="#drawable/ic_launcher_background" />
<!--text view for displaying course name-->
<TextView
android:id="#+id/idTVCourseName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_toEndOf="#id/idIVCourse"
android:layout_toRightOf="#id/idIVCourse"
android:text="DSA Self Paced Course"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<!--text view for displaying course tracks-->
<TextView
android:id="#+id/idTVCourseTracks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/idTVCourseName"
android:layout_marginTop="10dp"
android:layout_toEndOf="#id/idIVCourse"
android:layout_toRightOf="#id/idIVCourse"
android:text="Course Tracks : 30"
android:textColor="#color/black"
android:textSize="15sp" />
<!--text view for displaying course duration-->
<TextView
android:id="#+id/idTVCourseDuration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/idTVCourseTracks"
android:layout_marginTop="10dp"
android:layout_toEndOf="#id/idIVCourse"
android:layout_toRightOf="#id/idIVCourse"
android:text="Course Duration : 4 Months"
android:textColor="#color/black"
android:textSize="15sp" />
<!--button for dismissing our dialog-->
<Button
android:id="#+id/idBtnDismiss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/idIVCourse"
android:layout_margin="10dp"
android:text="Dismiss dialog"
android:textAllCaps="false" />
</RelativeLayout>
</RelativeLayout>
where #drawable/rounded_top_corners will be:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#android:color/white" />
<corners android:topLeftRadius="30dp" android:topRightRadius="30dp"
android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
</shape>
2.You have to set a custom theme style for BottomSheetDialog with a Transparent window dialog like below:
val dialog = BottomSheetDialog(this, R.style.MyBottomSheetDialog)
where R.style.MyBottomSheetDialog is your custom BottomSheetDialog style defined in styles.xml like below:
<style name="MyBottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:colorBackground">#android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:backgroundDimAmount">0.3</item>
<item name="android:windowFrame">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
After the above changes you will have a Transparent Window BottomSheetDialog with a line on top like:
How do I remove this gap in a ConstraintLayout? The top is an ImageView with a top constraint to the top of the parent (ConstraintLayout).
Gap at the top between the toolbar and banner
This is how my styles.xml looks like:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
My activity_main.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<ImageView
android:id="#+id/headerImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/header" />
<Button
android:id="#+id/addlog_btn"
style="#android:style/Widget.DeviceDefault.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="108dp"
android:background="#drawable/newlogbtn"
android:fontFamily="#font/roboto_regular"
android:onClick="createNewLog"
android:paddingTop="72sp"
app:layout_constraintStart_toStartOf="#+id/headerImg"
app:layout_constraintTop_toTopOf="#+id/headerImg" />
<Button
android:id="#+id/addlog_btn2"
style="#android:style/Widget.DeviceDefault.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:background="#drawable/settingsbtn"
android:fontFamily="#font/roboto_regular"
android:paddingTop="72sp"
app:layout_constraintEnd_toEndOf="#+id/headerImg"
app:layout_constraintTop_toTopOf="#+id/addlog_btn" />
</androidx.constraintlayout.widget.ConstraintLayout>
My end goal is this:
I would like to achieve this with just editing the XML if it is possible, I tried to change the margins and padding's of both parent and I didn't do it right or it just doesn't seem to work.
You can remove this gap by adding android:scaleType="centerCrop" to the banner ImageView so that it will fill the entire assigned room to it.
So the layout will be after this change:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<ImageView
android:id="#+id/headerImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/header" />
<Button
android:id="#+id/addlog_btn"
style="#android:style/Widget.DeviceDefault.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="108dp"
android:background="#drawable/newlogbtn"
android:fontFamily="#font/roboto_regular"
android:onClick="createNewLog"
android:paddingTop="72sp"
app:layout_constraintStart_toStartOf="#+id/headerImg"
app:layout_constraintTop_toTopOf="#+id/headerImg" />
<Button
android:id="#+id/addlog_btn2"
style="#android:style/Widget.DeviceDefault.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:background="#drawable/settingsbtn"
android:fontFamily="#font/roboto_regular"
android:paddingTop="72sp"
app:layout_constraintEnd_toEndOf="#+id/headerImg"
app:layout_constraintTop_toTopOf="#+id/addlog_btn" />
</androidx.constraintlayout.widget.ConstraintLayout>
How to set layout drawable background using styles.xml? In the layout I'm using 2 drawable buttons.
When I using this in styles.xml all buttons change the background to what is in styles, but I want to change only the layout background.
<style name="menutheme">
<item name="android:background">#drawable/menu</item>
</style>
My layout:
<android.support.constraint.ConstraintLayout 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:theme="#style/menutheme"
android:contentDescription="#null"
tools:context="com.example.user.app.Activity2">
<RelativeLayout
android:layout_width="312dp"
android:layout_height="371dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.955">
<Button
android:id="#+id/entrycity"
android:layout_width="243dp"
android:layout_height="65dp"
android:layout_below="#+id/button3"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:background="#drawable/oval3"
android:fontFamily="#font/ultra"
android:text="#string/wybor2"
android:textColor="#android:color/background_light"
android:textSize="30sp"
tools:layout_editor_absoluteX="59dp"
tools:layout_editor_absoluteY="334dp" />
<Button
android:id="#+id/button3"
android:layout_width="243dp"
android:layout_height="65dp"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/entrycity"
android:background="#drawable/oval"
android:fontFamily="#font/ultra"
android:text="#string/wybor"
android:textColor="#android:color/background_light"
android:textSize="30sp"
tools:layout_editor_absoluteX="71dp"
tools:layout_editor_absoluteY="227dp" />
</RelativeLayout
</android.support.constraint.ConstraintLayout>
try WindowBackground instead of background. Like,
<style name="menutheme" parent="AppTheme">
<item name="android:windowBackground">#drawable/menu</item>
</style>
and you need to apply this theme to acivity in manifest. not in layout.
In my view, I would like a ripple effect to appear whenever a user touches an ImageView in the layout. I've tried wrapping the ImageView inside a RelativeLayout, but it hasn't worked. Here is the 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"
tools:context="com.sample.me.TapActivity" >
<RelativeLayout
android:id="#+id/tap_view_frame"
android:layout_width="#dimen/activity_tap_image_width"
android:layout_height="#dimen/activity_tap_image_height"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:clickable="true"
android:background="#drawable/ripple_view" >
<ImageView
android:id="#+id/tap_view"
android:src="#drawable/ram"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:clickable="true" />
</RelativeLayout>
<TextView
android:id="#+id/tap_name_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/white"
android:layout_marginLeft="#dimen/textview_horizontal_margin"
android:layout_alignParentLeft="true"
android:layout_above="#+id/tap_number_textView"/>
<TextView
android:id="#+id/tap_number_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:layout_marginBottom="#dimen/textview_vertical_margin"
android:layout_alignLeft="#+id/tap_name_textView"
android:layout_alignBottom="#+id/tap_view_frame" />
<android.support.v7.widget.CardView
android:id="#+id/tap_card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/cardview_horizontal_margin"
android:layout_marginRight="#dimen/cardview_horizontal_margin"
android:layout_marginTop="#dimen/cardview_vertical_margin"
android:layout_below="#+id/tap_view_frame">
<android.support.v7.widget.RecyclerView
android:id="#+id/tap_options_recyclerview"
android:layout_width="match_parent"
android:layout_height="#dimen/cardview_tap_height" />
</android.support.v7.widget.CardView>
And here is the "ripple_view" drawable:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffa0a0a0">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#ffa0a0a0"/>
</shape>
</item>
</ripple>
I have also tried adding in the android:background="?android:attr/selectableItemBackground" tag, but that didn't seem to help. Can anyone explain why the ripple is not showing up? I used the same method to enable the effect in my custom buttons and RecyclerView rows, but it is not working for the RelativeLayout. Ideally, I would like to avoid using a third party library for something as simple as this.
I have to make another highlight color for ListView item. I use custom adapter for items, and i have following code:
Layout:
<?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="fill_parent"
android:background="#FFFFFF"
android:weightSum="1.0"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_weight="0.13"
android:background="#drawable/booklist_header"
android:orientation="horizontal"
android:layout_height="0dp" >
<ImageView
android:id="#+id/imageViewBookListBack"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:src="#drawable/back_button" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_weight="0.77"
android:layout_height="0dp" >
<ListView
android:id="#+id/listViewCurrentList"
android:listSelector="#drawable/selector"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutBooklistAdwhirl"
android:layout_width="fill_parent"
android:layout_weight="0.1"
android:layout_height="0dp" >
</LinearLayout>
</LinearLayout>
Code for item layout:
<?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="fill_parent"
android:background="#FFFFFF"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageViewBookListItemImage"
android:layout_width="120dp"
android:layout_marginTop="15dp"
android:layout_height="120dp" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="135dp"
android:layout_marginTop="15dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textViewBookListItemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textColor="#000000"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textViewBookListItemAuthor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
Code for selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="#color/green" /> <!-- focused -->
<item android:state_focused="true" android:state_pressed="true" android:drawable="#color/green" /> <!-- focused and pressed-->
<item android:state_pressed="true" android:drawable="#color/green" /> <!-- pressed -->
<item android:drawable="#color/green" /> <!-- default -->
</selector>
Code for color.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="green">#006400</color>
<color name="white">#FFFFFF</color>
</resources>
But I have a problem: ListView item doesn't change color by click! It has white color always. Where have I made mistake?
This is how you do it:
First, in your ListView, put the following:
android:listSelector="#00000000"
This makes your listSelector (the color you normally see when you click the listview) transparent.
Next, set the LinearLayout of your item layout to this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/selector"
android:orientation="horizontal" >
I had the same problem a few days ago and it took me ages to figure this out. Hopefully it works for you!
You can try to add this: android:drawSelectorOnTop="true" to the definition of the ListView.
Hope this will help you!
P.S. You can optimize your main layout and remove the unnecessary layouts. You can use layoutopt for this.
android:drawSelectorOnTop="true"
Even if this is late to the question, I came to a simpler solution, which I would like to share even for my future self:
In your ListView just set
android:listSelector="#drawable/selector"
In your List Item you need to remove the background.