Rating bar with custom size - android

I have to display rating bar with my custom size. But in the case that rating bar with my custom size, the stars disappear in my layout. Can I manage the size of padding and margin the rating bar?
<RatingBar
android:focusable="false"
android:id="#+id/rating_order"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:numStars="5"
android:stepSize="1.0"
android:scaleX="0.3"
android:scaleY="0.3" />

You can try to set the parameters from styles:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar" >
<item name="android:numStars">5</item>
<item name="android:stepSize">1.0</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingBottom">44dp</item>
<item name="android:layout_marginLeft">4dp</item>
<item name="android:layout_marginTop">4dp</item>
</style>
<resources />
And then in your RatingBar add a style:
style="#style/CustomRatingBar"

Related

Assign attributes such as app:strokeWidth in style

I want to create a style 100% equal to this button:
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_xml"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:backgroundTint="#color/red"
android:text="In XML"
android:textStyle="bold"
app:cornerRadius="25dp"
app:strokeColor="#color/black"
app:strokeWidth="2dp"/>
This is the style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="id" name="btn_xml" value="btn_xml" />
<style name="ProgrammaticallyStyle">
<item name="android:id">#id/btn_xml</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_margin">5dp</item>
<item name="android:backgroundTint">#color/red</item>
<item name="android:paddingStart">30dp</item>
<item name="android:paddingEnd">30dp</item>
<item name="android:text">In XML</item>
<item name="android:textStyle">bold</item>
<item name="app:cornerRadius">25dp</item>
<item name="app:strokeColor">#color/black</item>
<item name="app:strokeWidth">2dp</item>
</style>
</resources>
But in style, the last 3 attributes start with app:xxx and cannot be assigned. I assumed that is because in xml I have the following sentence in button parent view:
xmlns:app="http://schemas.android.com/apk/res-auto"
Using sttributes without app: doesn't work, do I maybe need a specific parent for the style?
How can I assign these app:xxx attributes in style?

How to center title in default toolbar without custom layout?

I have this Theme and want to center the title in the default toolbar. This means that I have no Toolbar in my XML file. This is what I have tried:
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="android:textColor">#color/colorWhite</item>
<item name="actionBarTheme">#style/AppBaseTheme.Toolbar</item>
</style>
<style name="AppBaseTheme.Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="android:textColorPrimary">#color/colorPrimary</item>
<item name="titleCentered">true</item>
</style>
Where <item name="titleCentered">true</item> doesn't center the title. How to solve this?
In your Activity, in your onCreate()
methodgetSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM;
getSupportActionBar().setCustomView(R.layout.main_layout);
main_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/tvTitle"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#FFFFFF" />

How To Change Action Bar Text Color

How can i change my action bar text color White to Black ? I don't want to use the Action Bar Sherlock .
Here Is My Code For Action Bar .
ActionBar ab = getActionBar();
ab.setDisplayUseLogoEnabled(false);
ab.setDisplayShowHomeEnabled(true);
ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
ab.setCustomView(R.layout.actionbar);
ab.setDisplayHomeAsUpEnabled(true);
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#33CCFF"));
ab.setBackgroundDrawable(colorDrawable);
Here is Custom View For Action Bar :
<?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="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/title"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
Here style.xml :
<resources>
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
May I know what is the correct way to achieve my objective?Maybe this question too basic, but i did't find any suitable solution.Please Help me out.
Try this styles:
You can edit your TitleTextStyle inside of styles:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle"parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/black</item>
</style>
</resources>
Here is the styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle"parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle"
parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
</style></resources>
thanx to rnoway
<?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="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/title"
android:textColor="#ffffff" // change the color code your wat , instead of #ffffff put youra
android:textSize="24sp" />
u can find the color codes from
http://www.w3schools.com/tags/ref_colorpicker.asp
Just use html to set the title, and specify the text color. For example, to set the ActionBar text color to red, simply do this:
getActionBar()/* or getSupportActionBar() */.setTitle(Html.fromHtml("<font color=\"#000000\">" + getString(R.string.app_name) + "</font>"));

Why size of rating bar not decreasing?

I want to decrease the size of the rating bar, but I'm unable to do so. I have tried to apply on rating bar still there is no change on rating bar size.
Please help
Here is style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Light" />
<style name="ratingBar" parent="#android:style/Widget.RatingBar">
<item name="android:maxHeight">10dip</item>
<item name ="android:maxWidth">10dip</item>
</style>
</resources>
main.xml
<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" >
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginBottom="58dp"
style="#style/ratingBar" />
</RelativeLayout>
You need to set the drawable for the stars
<style name="RatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_stars</item>
<item name="android:minHeight">32dp</item>
<item name="android:maxHeight">32dp</item>
</style>
<style name="RatingBar.Small" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_stars_small</item>
<item name="android:minHeight">22dp</item>
<item name="android:maxHeight">22dp</item>
</style>

actionbarsherlock TitleTextStyle not working

I have the following style for my the ActionBar in my project
<style name="Theme.MyTheme" parent="Theme.Sherlock.Light">
<item name="actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="homeAsUpIndicator">#drawable/icon_back</item>
<item name="android:homeAsUpIndicator">#drawable/icon_back</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#0099CC</item>
<item name="android:height">?android:attr/actionBarSize</item>
<item name="background">#0099CC</item>
<item name="android:titleTextStyle">#style/Theme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/Theme.ActionBar.TitleTextStyle</item>
<item name="android:displayOptions">useLogo|showTitle|homeAsUp</item>
<item name="displayOptions">useLogo|showTitle|homeAsUp</item>
</style>
<style name="Theme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:padding">10dp</item>
</style>
Now the text in the title bar is 0dp aligned to the left. The TextColor attribute works fine but the padding seems to be ignored. As a result, the title of the Activity is stuck to the left hand of the screen that is not very pleasing to look at. How can i add padding to the text ?
Kind Regards,
To archive haveing a centered title in the ABS, without having the home button, you could just do this:
In your Activity, in your oncreate methode:
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.abs_layout);
abs_layout:
<?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="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="my Title"
android:textColor="#ffffff"
android:id="#+id/mytext"
android:textSize="25dp" />
</LinearLayout>
Now you should have a Actionbar wih just a Title. If you want to set a custom background, set it in the Layout above(but then don't forget to set android:layout_height="match_parent")
or with:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.yourimage));
This is how I was able to set the padding between the home icon and the title.
ImageView view = (ImageView)findViewById(android.R.id.home);
view.setPadding(left, top, right, bottom);
I couldn't find a way to customize this via the ActionBar xml styles though. That is, the following XML doesn't work:
<style name="ActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/ActionBarTitle</item>
<item name="android:icon">#drawable/ic_action_home</item>
</style>
<style name="ActionBarTitle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">18sp</item>
<item name="android:paddingLeft">12dp</item> <!-- Can't get this padding to work :( -->
</style>
from here:
Padding between ActionBar's home icon and title

Categories

Resources