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"
Related
I want to arrange buttons evenly on the layout using styles to make my code simple. So why buttons have different distance between each other and ViewGroup? Am I right that attributes defined in the xml file overrides style's attributes?
// xml code for the activity
<?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">
<Button
style="#style/style1"
android:id="#+id/b1"
android:text="button1"
app:layout_constraintBottom_toTopOf="#+id/b2" />
<Button
style="#style/style1"
android:id="#+id/b2"
android:text="button2"
app:layout_constraintTop_toBottomOf="#+id/b1"
app:layout_constraintBottom_toTopOf="#+id/b3" />
<Button
style="#style/style1"
android:id="#+id/b3"
android:text="button3"
app:layout_constraintTop_toBottomOf="#+id/b2"/>
</androidx.constraintlayout.widget.ConstraintLayout>
// used style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="style1">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">10dp</item>
<item name="android:textColor">#color/teal_200</item>
<item name="layout_constraintTop_toTopOf">parent</item>
<item name="layout_constraintLeft_toLeftOf">parent</item>
<item name="layout_constraintRight_toRightOf">parent</item>
<item name="layout_constraintBottom_toBottomOf">parent</item>
</style>
</resources>
What the three buttons have in common is layout_constraintEnd_toEndOf and layout_constraintStart_toStartOf.
So in style you will only define these two attributes of layout_constraint.
STYLE
<style name="style1" parent="Widget.AppCompat.Button.Colored">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">10sp</item>
<item name="android:textColor">#color/teal_200</item>
<!-- layout_constraint attributes -->
<item name="layout_constraintEnd_toEndOf">parent</item>
<item name="layout_constraintStart_toStartOf">parent</item>
</style>
your_activity.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=".YourActivity">
<Button
android:id="#+id/b1"
style="#style/style1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#+id/b2"
/>
<Button
android:id="#+id/b2"
style="#style/style1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2"
app:layout_constraintTop_toBottomOf="#+id/b1"
app:layout_constraintBottom_toTopOf="#+id/b3"
/>
<Button
android:id="#+id/b3"
style="#style/style1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button3"
app:layout_constraintTop_toBottomOf="#+id/b2"
app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
With this code, AndroidStudio will point out an error in the xml file, after all the ConstraintLayout was not made to define its attributes from style. But your app will run normally.
Don't forget to put your your ActivityClass in tools:context=".ActivityClass".
Tip: when you want to set a text size in any android xml, you should use "sp" instead of "dp".
Example
Incorrect:
<item name="android:textSize">10dp</item>
Correct
<item name="android:textSize">10sp</item>
I added a style for a checkbox like below
<style name="SurveyCheckBox" >
<item name="colorControlNormal">#color/colorPrimaryLight</item>
<item name="colorControlActivated">#color/colorSecondary</item>
<item name="colorControlHighlight">#color/colorSecondaryDark</item>
</style>
It works perfectly but I also added this style for checkboxes created dynamically in a recycler view. In this case, style does not affect checkboxes. To solve this problem, I added "android:" before the item name.
<style name="SurveyCheckBox" >
<item name="android:colorControlNormal">#color/colorPrimaryLight</item>
<item name="android:colorControlActivated">#color/colorSecondary</item>
<item name="android:colorControlHighlight">#color/colorSecondaryDark</item>
</style>
This property works in API >=21 but does not work <21. Is there any solution for this problem?
recycler_view_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="#+id/survey_check_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="8"
android:textColor="#color/colorOnBackground"
android:textSize="16sp" />
<CheckBox
android:id="#+id/survey_check_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:theme="#style/SurveyCheckBox" /> </LinearLayout>
Have you tried with android.support.v7.widget.AppCompatCheckBox instead of CheckBox ?
I'm new to Stackoverflow but not that new to coding.
I have this simple flyer I made in Android Studio.
I'm trying to apply different styles to different TextViews.
The first two styles shown work on all TextViews but the third style named "address_style" won't apply for some reason.
The TextView goes away completely when I apply it as a style.
I've tried a couple of different things.
I just don't get why the third style won't work.
Can someone help me out?
<?xml version="1.0" encoding="UTF-8" ?>
<style name="Title">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#000000</item>
<item name="android:text">#string/Title</item>
<item name="android:textColor">#2196F3</item>
<item name="android:textSize">18sp</item>
</style>
<style name="textView">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">#CCBBDEFB</item>
<item name="android:paddingTop">12dp</item>
<item name="android:textColor">#F44336</item>
<item name="android:textSize">15sp</item>
</style>
<style name="address_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingTop">14dp</item>
<item name="android:text">#string/address</item>
<item name="android:background">#CCBBDEFB</item>
<item name="android:textColor">#000000</item>
<item name="android:textSize">16sp</item>
</style>
<!-- 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>
<?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"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="#drawable/soccer" />
<TextView
android:id="#+id/title"
style="#style/Title"
android:fontFamily="#font/hanalei_fill"
android:text="#string/Title" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:background="#000000"
android:fontFamily="#font/trade_winds"
android:paddingTop="10dp"
android:text="#string/textUnderTitle"
android:textColor="#03A9F4"
android:textSize="20sp" />
<TextView
android:id="#+id/textView3"
style="#style/textView"
android:layout_below="#id/textView2"
android:fontFamily="#font/carter_one"
android:text="#string/price" />
<TextView
android:id="#+id/textView4"
style="#style/textView"
android:layout_below="#id/textView3"
android:fontFamily="#font/carter_one"
android:text="#string/seasons" />
<TextView
android:id="#+id/textView5"
style="#style/textView"
android:layout_below="#id/textView4"
android:fontFamily="#font/carter_one"
android:text="#string/whatYouLearn" />
<TextView
android:id="#+id/textView6"
style="#style/textView"
android:layout_below="#id/textView5"
android:fontFamily="#font/carter_one"
android:text="#string/allAges" />
<TextView
style="#style/textView"
android:layout_above="#id/register"
android:fontFamily="#font/trade_winds"
android:text="#string/address" />
<TextView
android:id="#+id/register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:autoLink="all"
android:background="#000000"
android:fontFamily="#font/carter_one"
android:gravity="center_horizontal"
android:text="#string/web_address"
android:textColor="#2196F3"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
So, I feel stupid. I finally saw the little red exclamation point in the red stop sign in my preview of the activity_main box. It told me one of the styles is not registering(address_style) and gave me an option to refresh the styles.xml page. And now it works. I didn't know that could cause an error because there were no problems with the other two styles I created.
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
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