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
Related
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:
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>
I want to change my default Rating bar Star(*) icon to another icon.
Can anybody help me out..
My Code: XML
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
style="#style/foodRatingBar"
android:isIndicator="false"
android:layout_centerHorizontal="true"
android:layout_marginTop="86dp"
android:numStars="4" />
Styles.xml:
<style name="foodRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/selector</item>
<item name="android:minHeight">23dip</item>
<item name="android:maxHeight">25dip</item>
</style>
Selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#android:id/background"
android:drawable="#drawable/ic_fuel_gray"/>
<item
android:id="#android:id/secondaryProgress"
android:drawable="#drawable/ic_fuel_gray"/>
<item
android:id="#android:id/progress"
android:drawable="#drawable/ic_fuel_color"/>
</layer-list>
But outPut is:
Just add below two snippets and you are done:
<style name="customRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/custom_image1</item>
<item name="android:indeterminateDrawable">#drawable/custom_image2</item>
</style>
and Use above style in your xml where rating bar is used:
<RatingBar style="#style/customRatingBar" ... />
Add replace your Rating bar code with this and check if it is showing in preview?
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/customRatingBar"
/>
<RatingBar
android:id="#+id/ratingBar"
style="#style/foodRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:numStars="5"
android:rating="5"
android:transformPivotX="0dp"
android:transformPivotY="0dp"
android:isIndicator="false"/>
try this
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">
Please have a look at the following code
<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:descendantFocusability="afterDescendants"
android:background="#drawable/background1"
tools:context=".Form" >
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/dateTxt"
android:textSize="32sp"
android:textColor="#FFFFFF"
android:layout_alignParentLeft="true"
/>
<DatePicker
android:id="#+id/datePick"
android:layout_toRightOf="#+id/txt1"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
/>
</RelativeLayout>
In here, I need to make the text of TextView Bold, and if possible, add a text design something like "spread", "spoiled", "blur".
How can I do this? Making the text bold is the main question, if you can please answer to the second question as well.
Thanks
TextView t1=(TextView)findViewById(R.layout.TextView01);
t1.setTypeface(null,Typeface.BOLD);
For design get some idea from it..
http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-basic-font-sizes/
To do it via XML I recommend you to create a style. If you don't have any, add a XML file to your 'values' folder named "styles.xml" and add this style to it (I used shadows to try to make some blurry text, but it may not be very effective), anyway you have the bold text as you wanted:
<resources>
<style name="Text"> </style>
<style name="Text.Strong">
<item name="#android:textSize">32sp</item>
<item name="#android:paddingLeft">4dp</item>
<item name="#android:paddingBottom">4dp</item>
<item name="#android:textColor">#FFFFFFFF</item>
<item name="#android:textStyle">bold</item>
</style>
<style name="Text.Strong.Blurry">
<item name="#android:shadowColor">#BBBBBB</item>
<item name="#android:shadowDx">1</item>
<item name="#android:shadowDy">1</item>
<item name="#android:shadowRadius">10</item>
</style>
</resources>
Then just apply the style to your TextView:
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/dateTxt"
android:layout_alignParentLeft="true"
style="#style/Text.Strong.Blurry" />
Modify Your dateTxt String. Use bold tag.
<string name="dateTxt"><b> Copyright </b></string>
And for blurry or spoil text , you can make style and then apply on your textView. For doing text blur use this
<style name="Theme.BlurText" parent="android:style/Theme.Translucent">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:background">#android:color/transparent</item>
</style>
And in your textview use
android:style="#style/Theme.BlurText"