As the title says I nedd an activity with black transparent background and a SearchView on top of it with white background and gray/custom text/icon colors.
This is what I have so far:
activity_search_input.xml:
<?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=".SearchInput">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="58dp"
android:layout_height="60dp"
android:background="#FFFFFF"
app:layout_constraintEnd_toStartOf="#+id/searchInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_back" />
</androidx.constraintlayout.widget.ConstraintLayout>
<SearchView
android:id="#+id/searchInput"
android:layout_width="0dp"
android:layout_height="60dp"
android:background="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/constraintLayout"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Even though the background is set to #FFFFFF it is gray!
in manifest:
<activity
android:name=".SearchInput"
android:theme="#style/Theme.AppCompat.Translucent">
</activity>
in styles.xml:
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#66000000</item> <!-- Or any transparency or color you need -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
How can I do that? I'm already searching since couple hours for a solution for such a minor thing! Android is absolutely horrendous!
True testing this out was indeed a horrendous experience unless there's an easy method I'm unaware of. Here's a workaround I found for your case.
The main issue is this line <item name="android:background">#66000000</item> in your Translucent style, that messes up the colors which the searchView uses behind the scenes. Remove that and the background you set for searchView should be working now.
But you'll notice all the icons and textcolor remain white you will have to either individually set these with custom icons (for some reason the textColor still wouldn't change) or simply use parent="Theme.AppCompat.Light.NoActionBar" as the parent for your translucent theme.
So now your custom Translucent theme should look like below:
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
Now since you have removed the window background from theme you will need to set a background to the root layout using android:background="#66000000"
So your activity_search_input.xml:
<?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"
android:background="#66000000"
tools:context=".SearchInput">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="58dp"
android:layout_height="60dp"
android:background="#FFFFFF"
app:layout_constraintEnd_toStartOf="#+id/searchInput"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_back" />
</androidx.constraintlayout.widget.ConstraintLayout>
<SearchView
android:id="#+id/searchInput"
android:layout_width="0dp"
android:layout_height="60dp"
android:background="#FFFFFF"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/constraintLayout"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
The result was this
Tried different ways but this felt the easiest, check if this helps you out, or maybe someone will come up with a better method.
Related
I am trying to set cursor/hint/icon color of my SearchView in white. Defined the style for it but SearchView is not updating it is showing in black. Kindly suggest what is missing in my code.
styles.xml
<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView.ActionBar" >
<item name="android:textColorPrimary">#color/color_white</item>
<item name="android:textColorHint">#color/color_white</item>
<item name="android:tint">#color/color_white</item>
<item name="queryHint">#string/search_hint</item>
</style>
colors.xml
<color name="color_white">#FFFFFF</color>
SearchView defined in a layout:
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary">
<-- other views code -->
<SearchView
style="#style/SearchViewStyle"
android:id="#+id/header_search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:layoutDirection="rtl"
android:iconifiedByDefault="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
UI on phone screen:
Use androidx.appcompat.widget.SearchView and not SearchView.
SearchView doesn't know what "Widget.AppCompat.SearchView.ActionBar" means.
Hy
I created an android project, and I saw thet, tehe are two themes.xml file. In emulator, when I switch day and night mode, my application color schema is changes too.
I thought it is greate, because with thease themes it will be easy to create a day/night app, but I don't know how it works.
How can I define a new color item inside themes, and use this schema for layout background?
For example: There is an item in both themes
<item name="colorPrimary">#303F9F</item>
And I would like to create a new item for both themes.xml, and use it to set up fragment background color, but the intellisense doesn't find this element directly.
<item name="backgroundColor">#303F9F</item>
You can change color easily from where you define your theme in 'styles.xml'.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" 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>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorSecondary</item>
<item name="colorPrimaryDark">#color/colorSecondaryDark</item>
<item name="colorAccent">#color/colorSecondaryAccent</item>
</style>
I have two themes in my app so if i change the color or anything in my theme i will define that color in my selected theme for example:
i want to change the background color of 'AppThemeDark' i just define the color like this
<item name="background">#color/"#fff67"</item>
copy this line in your first screen
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
Ok In constraintlayout background tag is not worked so I will fix this problem with the use of View.
<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:background="#AAA">
<View
android:id="#+id/background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#FFF"
app:layout_constraintBottom_toBottomOf="#+id/textView3"
app:layout_constraintEnd_toEndOf="#+id/textView1"
app:layout_constraintStart_toStartOf="#+id/textView1"
app:layout_constraintTop_toTopOf="#+id/textView1" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="#+id/textView1"
app:layout_constraintStart_toStartOf="#+id/textView1"
app:layout_constraintTop_toBottomOf="#+id/textView1"
tools:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="#+id/textView1"
app:layout_constraintStart_toStartOf="#+id/textView1"
app:layout_constraintTop_toBottomOf="#+id/textView2"
tools:text="TextView" />
</android.support.constraint.ConstraintLayout>
I am trying to create an activity that will match the parent height. When I am testing the application on Pixel XL the application is fine, but when install on Xiaomi Redmi Note 9 Pro I have one part of the screen that it's not covered. This is the part above the camera, and it might be that my question is not only for this phone but I guess for all the others with the same design.
This is how it looks on pixel and it's ok:
And this is how it looks on Xiaomi Redmi Note 9 Pro:
This is my activity 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:background="#color/main_screen_background"
tools:context=".activty.WelcomeActivity">
<include layout="#layout/toolbar" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/main_menu_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:layout_marginTop="20dp"
android:layout_marginBottom="60dp" />
</RelativeLayout>
And this is my Toolbar if needed:
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/main_screen_background"
android:theme="#style/AppFullScreenTheme"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<RelativeLayout
android:id="#+id/test_menu_language_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp">
<ImageView
android:id="#+id/about_dropdown_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_ikonki_potrosuvaci_02" />
<TextView
android:id="#+id/language_dropdown_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:text="MK"
android:textColor="#color/white"
android:textSize="20dp" />
</RelativeLayout>
</androidx.appcompat.widget.Toolbar>
What I want to achieve is to have covered also that black part and have the color from the activity, probably an easy thing but I am little rusty with android. I checked the other applications and they are covering that part.
So actually there are only two lines of code needed to be added in your v27/styles.xml:
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, never -->
</item>
<item name="android:windowTranslucentStatus">true</item>
The first will cover that area and the second will set the color of the activity to that area. This is how my styles.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowLayoutInDisplayCutoutMode">
shortEdges <!-- default, shortEdges, never -->
</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:textAppearanceLargePopupMenu">#style/myPopupMenuTextAppearanceLarge
</item>
<item name="android:textAppearanceSmallPopupMenu">#style/myPopupMenuTextAppearanceSmall
</item>
</style>
</resources>
Finally I have applied this style to every activity that I have.
I want to make the same toolbar. Everything is perfect but can not get the shadow as the picture shows. I design the whole things but can not get the shadow. Can anyone plz guide me. I m posting my code below and attaching the image below:
layout design image
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.cardview.widget.CardView
android:id="#+id/cvToolbar"
style="#style/materialCardView"
android:layout_width="match_parent"
android:layout_height="#dimen/dp_56"
android:layout_marginStart="#dimen/dp_8"
android:layout_marginTop="#dimen/dp_8"
android:layout_marginEnd="#dimen/dp_8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/ivToolbarBack"
android:layout_width="#dimen/dp_0"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/dp_23"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_arrow_back" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tvToolbarTitle"
style="#style/pinVerificationToolbarTextStyle"
android:layout_width="#dimen/dp_0"
android:layout_height="#dimen/dp_40"
android:layout_marginStart="#dimen/dp_24"
android:layout_marginTop="#dimen/dp_11"
android:layout_marginEnd="#dimen/dp_8"
android:layout_marginBottom="#dimen/dp_5"
android:gravity="top"
android:text="#string/pos_system"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/ivToolbarBack"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<style name="pinVerificationToolbarTextStyle">
<item name="android:textAppearance">#style/TextAppearance.Text.Regular</item>
<item name="android:textColor">#color/colorBlack</item>
<item name="android:textSize">22sp</item>
<item name="android:letterSpacing">-0.01</item>
<item name="android:textStyle">bold</item>
<item name="fontFamily">#font/martel_sans</item>
</style>
<style name="materialCardView">
<item name="cardBackgroundColor">#color/colorWhite</item>
<item name="cardCornerRadius">26dp</item>
<item name="cardElevation">1dp</item>
<item name="elevation">1dp</item>
<item name="android:translationZ">3dp</item>
</style>
can somebody please help me to resolve.
you can use android:background="#android:drawable/dialog_holo_light_frame" to get shadow also you can make a background drawable using any drawing software like photoshop ,xd etc
you can see this as a reference Android View shadow
Just add android:elevation=“6dp” in your toolbar
In your onCreate method of your activity code add the following code:
kotlin code:
supportActionBar?.elevation = 8F
java code:
getSupportActionBar().setElevation(8);
------------------------OR-----------------
kotlin code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
actionBar?.elevation = 8F
}
java code:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getActionBar().setElevation(8);
}
to achieve 8dp of elevation in your app bar. (adding elevation is going to add shadow)
You can change the numeric value to achieve the desired elevation(shadow)
I have a window in an Android app which does not size correctly. The goal is to make the window wrap it's content (the TextView-s and the two Button-s), so it's a window in the middle of the screen, but it's height remains the whole screen despite my every attempt.
Image:
As you can see from the code, blue is the background of the included layout, black is the background of the main layout (for debug purposes).
Code/layout:
XML of the activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="#+id/NotificationLayout"
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="wrap_content"
android:background="#000FF0"
tools:context="com.tenderportkft.sped_ex.DialogActivity">
<include
android:id="#+id/NotificationDetails"
layout="#layout/auction_listitem_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toTopOf="#id/NotificationNoButton"
tools:layout_editor_absoluteX="8dp"/>
<Button
android:id="#+id/NotificationNoButton"
android:onClick="OkButtonClicked"
android:text="#string/AuctionPopup_NotInterestedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/NotificationDetails"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<Button
android:id="#+id/NotificationYesButton"
android:onClick="OkButtonClicked"
android:text="#string/AuctionPopup_OpenAuctionText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/NotificationNoButton"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
</android.support.constraint.ConstraintLayout>
XML of the included layout:
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
>
<TextView
android:id="#+id/TopRowText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="18sp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/BottomRowText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintHorizontal_bias="0.0"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="#+id/TopRowText"/>
</android.support.constraint.ConstraintLayout>
XML of the style of the window:
<style name="DialogActivityTheme"
parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/black</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>
Research: Researching this problem proved to be very hard as every single search result was either about problems with RelativeLayout-s or cases where the content is bigger than the window, not the other way. So my research mostly consisted of after not findig anything on google and here, randomly modifying height-settings of the layouts (and the style), so most combinations that seem logical are tried out and tested.
Platform: Android 6.0.1, API 23
EDIT: I know that floating windows are a discouraged way of displaying content, but I'm not responsible for the design, only the implementation.
EDIT2: Got closer to locating the problem - the included layout is the cause, and the solution is to replicate the contents that layout in my floating window instead of simply including the whole layout. Whether it's because of the fact of including or the specifics of the included layout is unclear.
try this
<style name="Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#color/black_20</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
<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:layout_margin="#dimen/_100dp"
android:background="#android:color/white"
tools:ignore="MissingPrefix">
// place components here
</RelativeLayout>
try this,
Window window = dialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);