I have a custom BottomSheetDialog and for its layout i created drawable which has top corners rounded rectangle. BottomSheetDialog layout background is a Linearlayout and i applied drawable to the layout.Top corners of the bottom sheet rounding correctly but there is a another layout bottom of the Linear Layout which is not rounded (square and white see below picture) and it is not in the layout.xml file. its like rounded rectangle on top of a square.I couldn't get rid of that square.
Below is my custom bottom sheet sample
public abstract class EmployeeBottomSheetDialog extends BottomSheetDialog {
private Context context;
private Activity activity;
private RecyclerView employeeRecyclerView;
private EditText searchEditText;
private DataBase dataBase;
private ArrayList<Employe> employeeList = new ArrayList<>();
private ArrayList<Employe> employeeSelectedList = new ArrayList<>();
private SelectEmployeeAdapter selectEmployeeAdapter;
private ImageButton closeSearchImageButton;
public EmployeeBottomSheetDialog(#NonNull Context context, List<Employe> selectedEmployeeList) {
super(context,R.style.BottomSheetDialogStyle);
this.context = context;
this.activity = (Activity) context;
if(!selectedEmployeeList.isEmpty()){
employeeSelectedList.clear();
employeeSelectedList.addAll(selectedEmployeeList);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.employee_bottom_sheet_dialog);
}
}
Below is my style
<style name="BottomSheetDialogStyle" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
<item name="shapeAppearanceOverlay">#style/ShapeAppearanceOverlay</item>
<item name="backgroundTint">#android:color/transparent</item>
<item name="background">#android:color/transparent</item>
</style>
below is my bottom sheet layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/transparent"
app:layout_behavior="#string/bottom_sheet_behavior">
<LinearLayout
android:id="#+id/dialog_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/bottom_sheet_background"
android:padding="10dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/ic_baseline_arrow_drop_down_24" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/between_two_views">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/search_wrapper"
style="#style/textInputHint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/search_employees">
<EditText
android:id="#+id/search"
style="#style/textInputText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<ImageButton
android:id="#+id/close_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginTop="15dp"
android:background="#null"
android:src="#drawable/ic_baseline_close_24"
android:text="Button" />
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/employee_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/between_two_views"/>
</LinearLayout>
</LinearLayout>
Below is my rounded corner drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:topLeftRadius="20dp" android:topRightRadius="20dp"/>
<solid android:color="#color/red" />
</shape>
To solve this, you need a transparent background color in your dialog style (BottomSheetDialogStyle):
<item name="android:colorBackground">#android:color/transparent</item>
For those looking for an easier way to implement rounded corners in all states, even EXPANDED state, then just define your BottomSheetDialog's background attribute to a shape drawable.
Here is the shape drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/sheet_gray"/>
<corners android:radius="24dp" />
</shape>
And this is my BottomSheetDialog :
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bs_bottomsheet"
android:background="#drawable/bottom_sheet_b"
app:behavior_hideable="false"
app:behavior_peekHeight="40dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
This will solve all the headaches about:
Setting a custom style and whatnot...
Wondering about how to round the corners in EXPANDED state
etc...
I found out the answer after hours of searching. i only needed to use below style
<style name="AppBottomSheetDialogTheme" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowSoftInputMode">adjustResize</item>
<item name="bottomSheetStyle">#style/AppModalStyle</item>
</style>
<style name="AppModalStyle" parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">#drawable/bottom_sheet_background</item>
</style>
<style name="BottomSheetStyle" parent="Theme.Design.BottomSheetDialog">
<item name="bottomSheetStyle">#style/Model</item>
</style>
<style name="Model" parent="Widget.Design.BottomNavigationView">
<item name="background">#drawable/bottom_sheet_layout</item>
</style>
Related
When I add a header to the navigation drawer I have this error
android.view.InflateException: Binary XML file line #0: Error
inflating class android.support.design.widget.NavigationView but
without header, it works properly.
first file is MainActivity it contains four fragments and bottom navigation
second is the acivity_main.xml layout
I think error may be in styles.xml file thats why I have put it also.
public class MainActivity extends AppCompatActivity {
private BottomNavigationView.OnNavigationItemSelectedListener
mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.home:
setTitle("Home");
HomeFragment fragmentTasks = new HomeFragment();
FragmentTransaction fragmentTransactionTasks = getSupportFragmentManager().beginTransaction();
fragmentTransactionTasks.replace(R.id.frame_layout, fragmentTasks);
fragmentTransactionTasks.commit();
return true;
case R.id.notification:
setTitle("Notification");
NoteFragment fragmentQA = new NoteFragment();
FragmentTransaction fragmentTransactionQa = getSupportFragmentManager().beginTransaction();
fragmentTransactionQa.replace(R.id.frame_layout, fragmentQA);
fragmentTransactionQa.commit();
return true;
case R.id.profile:
setTitle("Profile");
ProFragment fragmentCashOut = new ProFragment();
FragmentTransaction fragmentTransactionCashout = getSupportFragmentManager().beginTransaction();
fragmentTransactionCashout.replace(R.id.frame_layout, fragmentCashOut);
fragmentTransactionCashout.commit();
return true;
case R.id.help:
setTitle("Help");
HelpFragment fragmentDiscuss = new HelpFragment();
FragmentTransaction fragmentTransactionDiscuss = getSupportFragmentManager().beginTransaction();
fragmentTransactionDiscuss.replace(R.id.frame_layout, fragmentDiscuss);
fragmentTransactionDiscuss.commit();
return true;
}
return false;
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomNavigationView navigation =findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
setTitle("Home");
HomeFragment fragmentTasks = new HomeFragment();
FragmentTransaction fragmentTransactionTasks = getSupportFragmentManager().beginTransaction();
fragmentTransactionTasks.replace(R.id.frame_layout, fragmentTasks);
fragmentTransactionTasks.commit();
}
}
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hp.votingsystemv1.Activities.MainActivity">
<FrameLayout
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
app:menu="#menu/bottombar_menu"
app:itemTextColor="#color/colorIcons"
app:itemIconTint="#color/colorIcons">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
app:itemTextColor="#color/colorPrimaryText"
app:menu="#menu/drawer_menu"
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
android:fitsSystemWindows="true" />
</android.support.v4.widget.DrawerLayout>
//nav_header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="170dp"
android:background="#color/colorPrimary"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/iv_display_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:src="#drawable/no_image"
app:civ_border_color="#color/colorGrey"
app:civ_border_width="1dp"/>
<TextView
android:id="#+id/tv_display_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:textStyle="bold"
android:textSize="20sp"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
tools:text="Yousra Mahdi"/>
</LinearLayout>
//style.xml
<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>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppTheme1" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.ErrorTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textAppearance">#style/TextAppearance.AppCompat.Caption</item>
<item name="android:textColor">#color/colorPrimary</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<!-- Fullscreen application theme. -->
<style name="FullscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="Theme.MyDialog" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Dark.Dialog" parent="Theme.AppCompat.Dialog">
<item name="colorAccent">#color/colorIcons</item>
<item name="android:textColorPrimary">#color/colorAccent</item>
<item name="android:background">#color/colorGrey</item>
</style>
</resources>
I think you should try commenting CircleImageView and textview and test if it works. Some child view in nav_header might be having an issue getting inflated.
I have tried your code on my IDE and it works absolutely fine
I wish to create a simple dialog for the user with 2 buttons as follows:
Dialog Layout (dialog_layout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
android:orientation="vertical">
<Button
android:id="#+id/btn_select_choice_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="First Choice"
android:theme="#style/secondary_button_normal" />
<Button
android:id="#+id/btn_select_choice_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Second Choice"
android:theme="#style/secondary_button_normal" />
</LinearLayout>
secondary_button_normal:
<style name="secondary_button_normal" parent="Widget.AppCompat.Button">
<item name="colorButtonNormal">#color/button_secondary_normal_background</item>
<item name="android:textColor">#color/button_secondary_normal_text</item>
<item name="android:textSize">#dimen/button_textSize</item>
<item name="android:padding">#dimen/button_padding</item>
</style>
Activity's onCreate:
final Dialog selection = new Dialog(this);
selection.setContentView(R.layout.dialog_layout);
Button selectFirstChoice = (Button)selection.findViewById(R.id.btn_select_choice_1);
Button selectSecondChoice = (Button)selection.findViewById(R.id.btn_select_choice_2);
selectFirstChoice.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//do something
selection.dismiss();
}
});
selectSecondChoice.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//do something
selection.dismiss();
}
});
selection.setTitle("Some Title");
selection.setCancelable(false);
selection.show();
The preview is alright:
Preview
It works well on Nougat, but when I run it on Lollipop (5.0 and 5.1.1), the buttons are without styling, although the same button styling worked on activity buttons on Lollipop:
App
I wonder what could be going wrong, I also tried moving the Dialog into a DialogFragment but I faced the same behavior.
Found the following solution:
In my Styles.xml, I added:
<style name="dialog_button" parent="Theme.AppCompat.Light.Dialog">
<item name="colorButtonNormal">#color/button_secondary_normal_background</item>
<item name="android:textColor">#color/button_secondary_normal_text</item>
<item name="android:textSize">#dimen/button_textSize</item>
<item name="android:padding">#dimen/button_padding</item>
</style>
And in my custom dialog layout, I used that style as a theme for my buttons:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_margin="8dp"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_select_student"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/student"
android:theme="#style/dialog_button" />
<Button
android:id="#+id/btn_select_tutor"
android:layout_width="match_parent"
android:text="#string/tutor"
android:layout_height="wrap_content"
android:theme="#style/dialog_button" />
</LinearLayout>
I have created a circular progress-bar, and have made it follow as closely as possible to the design in the image below.
But I'm having difficulty having it match the design in the picture below (color, angle, shape etc.):
I don't know how to match :
the color of the above?
or the shape?
Design I'm wanting to follow:
My current design looks like the below:
My code so far is below:
activity_main.xml
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:id="#+id/progressBar"
android:layout_width="240dp"
android:layout_height="240dp"
android:indeterminate="false"
android:max="100"
android:progress="75"
android:progressDrawable="#drawable/style_circular_fill"
android:secondaryProgress="10"
android:layout_alignParentBottom="false"
android:layout_alignParentStart="false"
android:focusableInTouchMode="false"
android:layout_alignParentTop="true"
android:layout_marginTop="70dp"
xmlns:android="http://schemas.android.com/apk/res/android" />
style_circular_fill.xml
<item android:id="#android:id/secondaryProgress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true" >
<gradient
android:centerColor="#A9E2F3"
android:endColor="#A9E2F3"
android:startColor="#A9E2F3"
android:type="sweep" />
</shape>
</rotate>
</item>
<item android:id="#android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270" >
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true" >
<gradient
android:centerColor="#26ce61"
android:endColor="#26ce61"
android:startColor="#26ce61"
android:type="sweep" />
</shape>
</rotate>
</item>
You could try the CircleProgress library. One of the examples they feature looks quite similar to that of your requirement.
I haven't used it, so cannot confirm the ease of its use.
For the sake of being balanced, check out this list of Progress Bar libraries. There may be a library that can achieve the desired effect.
i suggest that u export the image to the match resources folders (mdpi,hdpi, and so on...);
after that create an animation xml file like this (let's call this file "progress_bar_animation.xml"):
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/your_resource_file_name"
android:pivotX="50%"
android:pivotY="50%"
android:duration="1"
android:fromDegrees="0"
android:toDegrees="1800" />
and then create a progress bar style (in style.xml file)
<style name="ProgressBar" parent="Base.Widget.AppCompat.ProgressBar">
<item name="android:indeterminateDrawable">#drawable/progress_bar_animation</item>
</style>
and finally add a progress bar to your xml and set the style you create before, like this:
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/ProgressBar" />
Use this progress dialogue
public class MyCustomProgressDialog extends ProgressDialog {
private Context c;
private ProgressWheel pd;
private ImageView imgLogo;
public MyCustomProgressDialog(Context context) {
super(context);
getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
c=context;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.progress_bar_loading);
}
#Override
public void show() {
super.show();
}
#Override
public void dismiss() {
super.dismiss();
}
}
progress_bar_loading.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="match_parent"
android:background="#color/transperent"
android:gravity="center"
>
<TextView
android:id="#+id/lbl_x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:text=" "
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"/>
<com.organigoal.customcontrol.ProgressWheel
android:id="#+id/progress_wheel"
xmlns:wheel="http://schemas.android.com/apk/res-auto"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
wheel:barColor="#color/grey"
wheel:progressIndeterminate="true"/>
After create and testing my custom dialog I've noticed that my button does not show any visual sign of change (such as the ripple effect or highlighting) when clicked. Does anyone know what I'm doing wrong and how to resolve this issue?
XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
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">
<Button
android:id="#+id/world"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:padding="10dp"
android:background="#color/green"
android:textColor="#color/white"
android:text="#string/world"
android:textAllCaps="false"
style="#android:style/TextAppearance.Medium"/>
</LinearLayout>
Java
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_other_lines) {
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_hello_world);
dialog.setTitle("Dialog");
Button world = (Button) dialog.findViewById(R.id.world);
world.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
return super.onOptionsItemSelected(item);
}
You override the default onClick effect by putting a background color.
android:background="#color/green"
You can do it by creating a custom background xml file on drawable, like this.
custom_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#color/Pressed_Color" />
<item android:state_activated="false" android:drawable="#color/green"/>
</selector>
then you call it on the button styling as like this:
android:background="#drawable/custom_background"
when you change your default appearance, you should handle different state if you want like this
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_sel" android:state_selected="true" />
<item android:drawable="#drawable/button_sel" android:state_pressed="true" />
<item android:drawable="#drawable/button_unsel" />
</selector>
save this as xml drawable and add as android:background
I have layer, it is transparent. I can click on button only, I want to click through layer.
Here's my Manifest:
<activity android:name=".Test" android:theme="#style/Theme.Transparent"/>
Here's Transparent theme style:
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
Here's my Activity code:
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
public class Test extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
// v I can touch through app, but cant click on button
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
// ^ I can touch through app, but cant click on button
Button xclose = (Button) findViewById(R.id.buttonx);
xclose.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
}
}
Here's my test.xml layout:
<?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="match_parent" >
<Button android:id="#+id/buttonx" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="X" />
</RelativeLayout>
Try this code and set click listener on the linear layout
<?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="match_parent" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ll">
<Button android:id="#+id/buttonx" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:text="X" />
</LinearLayout>
</RelativeLayout>
You already do the following here to set the click listener for the X button.
Button xclose = (Button) findViewById(R.id.buttonx);
xclose.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
finish();
}
});
Now all you need to do is the same thing but for the Layout which you have created that is transparent. So that when you click the layout in the area that your play button is, it listens to the click, rather than the button, as the button is out of reach.