Checkbox does not show after changing font - java

Hello I have a problem with displaying checkbox in alert dialog. It concern only a situation when the font is changed. On Arial everything (title , message and checkbox) shows correctly but on Ginger (AppThemeWithCustomFont) this Checkbox not shows at all (title and message works fine). Those are my codes.
checkbox.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"
android:id="#+id/layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10dp">
<CheckBox
android:id="#+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_horizontal"
android:buttonTint="#fff"
app:buttonTint="#fff"
android:text="#string/checkbox_show"
android:textColor="#fff"/>
StageZero.java
void configureInitDialog() {
AlertDialog adb = new AlertDialog.Builder(this, R.style.MojStyl).create();
View checkboxLayout = View.inflate(this, R.layout.checkbox, null);
skip = checkboxLayout.findViewById(R.id.skip);
adb.setView(checkboxLayout);
adb.setIcon(android.R.drawable.ic_dialog_info);
adb.setTitle("Info");
adb.setMessage(getResources().getString(R.string.stage_zero_dialog));
adb.setCancelable(false);
adb.setButton(DialogInterface.BUTTON_NEUTRAL, "Ok", (dialogInterface, i) -> {
String checkBoxResult = "";
if (skip.isChecked())
checkBoxResult = "linia2";
if (checkBoxResult.equals("linia2"))
editor.putBoolean("hideDialog", true).apply();
});
if (!hideDialog)
adb.show();
}
styles.xml
<style name="AppThemeWithClassicFont" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">#color/activity_background</item>
<item name="android:icon">#android:color/transparent</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="android:fontFamily">#font/arial</item>
<item name="android:actionBarStyle">#style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/ThemeActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
<!-- Application theme. -->
<style name="AppThemeWithCustomFont" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">#color/activity_background</item>
<item name="android:icon">#android:color/transparent</item>
<item name="colorPrimary">#android:color/transparent</item>
<item name="android:fontFamily">#font/ginger</item>
<item name="android:actionBarStyle">#style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/ThemeActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
I will give the best answer for any support. Thank you in advance!

I found a better way to customize the font on your check box, follow these steps to change the font:
1-Go to File/New/Folder/Assets Folder and create new Assets folser in the default location.
2-Copy your font into your new Assets folder.
3-Use this code inside the onCreate method to set your new font to the check box:
checkBox = findViewById(R.id.skip);
Typeface font = Typeface.createFromAsset(getAssets(), "YourFont.ttf");
checkBox.setTypeface(font);
This is the xml code that I used for the check box, in relative layout:
<CheckBox
android:id="#+id/skip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:buttonTint="#fff"
app:buttonTint="#1d1d1b"
android:text="hello world"
android:textColor="#1d1d1b"/>
But you can change and customize it.
That's the appearance that I got with my custom font:

Related

SearchView with border and text

I want to make my SearchView like this:
How can I implement in Java ?
What you see in the image is the Material TextInput with OutLined style. You can read more about that and the Filled style in the official docs here.
Also, don't forget you'll need material library for this. For that, do
implementation 'com.google.android.material:material:1.2.0-alpha06'
Now, what you can do with it is to make it like above by adding startDrawable and CornerRadius:
Create the XML widget as below and put a startIcon.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/editTextLayout"
style="#style/TextInputLayoutAppearanceOutLined"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Search View"
app:hintEnabled="true"
app:startIconDrawable=" *** Your ICON *** ">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textSize="12sp" />
</com.google.android.material.textfield.TextInputLayout>
Then, this is the style TextInputLayoutAppearanceOutLined, put it in your style.xml file:
<style name="TextInputLayoutAppearanceOutLined" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="hintTextAppearance">#style/HintText</item>
<item name="helperTextTextAppearance">#style/HintText</item>
<item name="android:textColor">#color/dark_grey</item>
<item name="android:textColorHint">#color/colorAccent</item>
<item name="hintTextColor">#color/colorAccent</item>
<item name="boxStrokeColor">#color/colorAccent</item>
<item name="startIconTint">#color/colorAccent</item>
<item name="boxBackgroundColor">#color/white</item>
<item name="boxCornerRadiusBottomEnd">#dimen/_26sdp</item>
<item name="boxCornerRadiusBottomStart">#dimen/_26sdp</item>
<item name="boxCornerRadiusTopEnd">#dimen/_26sdp</item>
<item name="boxCornerRadiusTopStart">#dimen/_26sdp</item>
<item name="boxStrokeWidthFocused">1dp</item>
<item name="hintEnabled">true</item>
<item name="hintAnimationEnabled">true</item>
<item name="colorControlNormal">#color/colorAccent</item>
<item name="colorControlActivated">#color/colorPrimary</item>
Obviously, you can set this in XML as well, but style gives you more control over your app to change the element everywhere by one edit.
Now, you'll have what you want your SearchView to look like, but further to make it act like a SearchView, you need to set filtering for your ListAdapter to make it work.
For that, you can look here.
make search view in layout file first
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/bg_round"/>
then the make drawable and name it bg_round and put the code below to that drawable
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff"/> // this the the inner background color
<stroke android:width="5dp" //this is for the stroke of the border
android:color="#android:color/black"/> //this is the stroke color
<corners android:radius="4cdp" /> //this is the corner radius
</shape>

How to change the style of SearchView?

I have to implement a SearchView in my application.
The XML declaration is as follows:
<SearchView
android:id="#+id/searchView"
style="#style/SearchViewStyle"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
The style is:
<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
<item name="android:searchIcon">#drawable/ico_search</item>
<item name="android:queryBackground">#android:color/transparent</item>
and finally in the activity:
SearchView mSearchView = findViewById(R.id.searchView);
mSearchView.setIconifiedByDefault(true);
mSearchView.setSubmitButtonEnabled(false);
mSearchView.setOnQueryTextListener(this);
mSearchView.setQueryHint("Search here");
I don't understand how to change the text color of the hint and the background of the "edittext" where I type the keywords used for the research.
What did I just try?
Add this line in the style.xml
<item name="android:textSize">18sp</item>
<item name="android:textColor">#color/white</item>
or add this in my activity
AutoCompleteTextView searchText = (AutoCompleteTextView) searchView.findViewById(R.id.abs__search_src_text);
searchText.setHintTextColor(getResources().getColor(color.black));
searchText.setTextColor(getResources().getColor(color.black));
Those solutions didn't work.
You can style your SearchView like this:
<style name="Theme.MyTheme" parent="Theme.AppCompat">
<item name="searchViewStyle">#style/MySearchViewStyle</item>
</style>
<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView">
<!-- Background for the search query section (e.g. EditText) -->
<item name="queryBackground">...</item>
<!-- Background for the actions section (e.g. voice, submit) -->
<item name="submitBackground">...</item>
<!-- Close button icon -->
<item name="closeIcon">...</item>
<!-- Search button icon -->
<item name="searchIcon">...</item>
<!-- Go/commit button icon -->
<item name="goIcon">...</item>
<!-- Voice search button icon -->
<item name="voiceIcon">...</item>
<!-- Commit icon shown in the query suggestion row -->
<item name="commitIcon">...</item>
<!-- Layout for query suggestion rows -->
<item name="suggestionRowLayout">...</item>
</style>
Here is details information https://philio.me/styling-the-searchview-with-appcompat-v21/
you can use EditeText insted of searchBox with same property by using shape:
<EditText
android:id="#+id/edt_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/shape_rectangle_edittext"
android:drawableRight="#drawable/ic_search_gray"
android:ems="10"
android:hint="#string/search_box"
android:imeOptions="actionSearch"
android:inputType="text"
android:padding="#dimen/size10"
android:textColorHint="#444"
android:textSize="#dimen/size16"
/>
and shape_rectangle_edittext.xml in drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#777"/>
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>

TextInputLayout change color on button click

I am having trouble changing the color of my TextInputLayout underline. Does anyone know how to change it 'On Click? it goes like this like..
onClick
if ( is true ) {
change textinputlayout underline color into red
} else {
non
}
Try to create a new style like this in your styles.xml TextAppearence.App.TextInputLayout, you then need to add colorControlActivated and colorControlHighlight.
<style name="TextAppearence.App.TextInputLayout"
parent="#android:style/TextAppearance">
<item name="android:textColor">#color/black</item>
<item name="android:textSize">#dimen/_13sdp</item>
<item name="colorControlNormal">#color/black</item>
//added attributes
<item name="colorControlActivated">#color/colorPrimary</item>
<item name="colorControlHighlight">#color/colorPrimary</item>
</style>
and change your color accordingly and use it here in styles.
You can do like this.
android:textColorHint="#FF0000" was EditText's hint color.
You can change android:textColor="#FF0000" in the EditText as text color.
You can add app:errorTextAppearance="#style/text_in_layout_error_hint_Style" to change the error text color.
And like this .
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColorHint="#FF0000"
app:errorTextAppearance="#style/text_in_layout_error_hint_Style"
app:hintTextAppearance="#style/text_in_layout_hint_Style"
app:errorEnabled="true">
<EditText
android:id="#+id/editEmail"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="-4dp"
android:digits="abcdefghijklmnopqrstuvwxyz.#0123456789"
android:hint="email / snipe id"
android:textAllCaps="false"
android:textColor="#FF0000"
android:textColorHint="#color/primary"
android:textSize="12sp"/>
</android.support.design.widget.TextInputLayout>
The LEFT-TOP hint color depended on app:hintTextAppearance="#style/text_in_layout_hint_Style".
And the style code:
<style name="text_in_layout_hint_Style">
<item name="android:textColor">#FF0000</item>
<item name="android:textSize">12sp</item>
</style>
Add error text style
<style name="text_in_layout_error_hint_Style">
<item name="android:textColor">#00ff00</item>
<item name="android:textSize">12sp</item>
</style>
like this:

How to set the title at center in android status bar

I changed tha status bar's color from styles.xml:
<resources>
<color name="custom_theme_color">#42A5F5</color>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/custom_theme_color</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
I also change the status bar's title from string.xml:
<resources>
<string name="app_name">Qu-easy</string>
<item name="colorPrimaryDark">#color/custom_theme_color</item>
</resources>
How can i set the title to the center of status bar?
I guess something like gravity.center?
try this one :-
Here you need to add one xml file
write following code in onCreate method
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_actionbar);
ActionBar.LayoutParams p = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
p.gravity = Gravity.CENTER;
custom_actionbar.xml Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="XYZ"
android:textColor="#ffffff"
android:id="#+id/mytext"
android:textSize="30dp"
android:textStyle="bold"/>
</LinearLayout>
This will definitely work for you

Android 21-22 Toolbar button turns black

My app is working perfectly but I have this problem that my toolbar button colour changes in version 21-22 to black.Here is the example how it looks normal:
And here is the problematic part on 21-22:
Here is my Toolbar and my style:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" 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/white</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
<style name="CustomToolBarTheme" parent="ThemeOverlay.AppCompat.Light">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
<item name="colorAccent">#color/white</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">18sp</item>
</style>
</resources>
The toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 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="wrap_content"
android:background="#color/colorPrimary"
android:paddingTop="#dimen/app_bar_top_padding"
app:theme="#style/CustomToolBarTheme">
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:maxLines="1"
android:layout_height="wrap_content"
android:textColor="#color/white"
android:textSize="19dp" />
</android.support.v7.widget.Toolbar>
I have tried to change the colour with SpannableString but it's not working.
Have you tried <item name="colorControlNormal">#color/colorwhatever</item> in your styles? (It should be in ToolBar text style)
I found the answer,it's in the toolbar just add the theme and the popupTheme like in my code and it will work.And you don't need that style andy more:
<android.support.v7.widget.Toolbar 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="wrap_content"
android:background="#color/colorPrimary"
android:paddingTop="#dimen/app_bar_top_padding"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">

Categories

Resources