background repeat image not working - android

I want to create a layout with a repeated background image. I searched and fount this tutorial
but seems not working for me!
the following shows activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/backrepeat"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/app_name" />
</LinearLayout>
and this is the backrepeat.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true"
android:src="#drawable/bg"
android:tileMode="repeat" />
also put backrepeat.xml in drawable folder.
Should I add or remove some codes?
thanks

Ok, here's what I've got in my app. It includes a hack to prevent ListViews from going black while scrolling.
drawable/app_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/actual_pattern_image"
android:tileMode="repeat" />
values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="app_theme" parent="android:Theme">
<item name="android:windowBackground">#drawable/app_background</item>
<item name="android:listViewStyle">#style/TransparentListView</item>
<item name="android:expandableListViewStyle">#style/TransparentExpandableListView</item>
</style>
<style name="TransparentListView" parent="#android:style/Widget.ListView">
<item name="android:cacheColorHint">#android:color/transparent</item>
</style>
<style name="TransparentExpandableListView" parent="#android:style/Widget.ExpandableListView">
<item name="android:cacheColorHint">#android:color/transparent</item>
</style>
</resources>
AndroidManifest.xml:
<application android:theme="#style/app_theme">

Related

How to increase the spaces between the stars in the custom rating bar in android?

I have designed the custom rating bar in android with different drawable images. I would like to increase the spaces between the stars in the rating bar.
I know there's a similar question with the same title., in which they've used a third party SDK to create spaces., But it doesn't worked out., Kindly do let me know how can I proceed further.
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<RatingBar
android:layout_width="wrap_content"
android:layout_height="#dimen/_30sdp"
style="#style/ImageRatingBar"
android:id="#+id/rate"
android:stepSize="1"
android:numStars="5"
android:layout_marginStart="#dimen/_20sdp"
android:layout_marginTop="#dimen/_20sdp"/>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
In my styles.xml:
<style name="ImageRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/ratingbar_selector</item>
<item name="android:minHeight">30dp</item>
</style>
In my drawables, the rating_bar_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/grey_star" />
<item
android:id="#android:id/secondaryProgress"
android:drawable="#drawable/yellow_star" />
<item
android:id="#android:id/progress"
android:drawable="#drawable/yellow_star" />
</layer-list>

How do I change the Background Color of a Lollipop Toolbar?

How do I change the background color of the Android Lollipop Toolbar in Xamarin Studio?
I've tried many different things with no luck, but here's what I've currently got, and it just doesn't work. Pay close attention to the images. For some reason, the bottom of the toolbar is colored (where the dropshadow should be) but not the background of the actual toolbar:
After adding all the styles and everything, in the Visual Designer, all I see is this (no color background):
My code:
styles.xml (located directly under resources folder):
<?xml version="1.0" encoding="UTF-8" ?>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:theme="#style/ActionBarThemeOverlay"
ndroid:background="?attr/colorPrimaryDark" />
Main.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#ffffffff">
<Toolbar
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar"
android:theme="#android:style/Theme.Material.Light" />
</LinearLayout>
Main.xml (Resources > menu > Main.xml):
<?xml version="1.0" encoding="UTF-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto">
<item android:icon="#android:drawable/ic_menu_share" android:id="#+id/menu_share" android:title="Share" android:showAsAction="ifRoom" />
</menu>
Anyone know how I can change the background color of the Toolbar?
UPDATE:
Main.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#ffffff">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="?actionBarSize"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:background="?attr/colorPrimary" />
</LinearLayout>
color.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<!-- Color : Classic colors -->
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
</resources>
styles.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat">
<!-- Value : Color -->
<item name="colorPrimary">#color/black</item>
<item name="colorAccent">#color/black</item>
</style>
</resources>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="ToolbarSample.ToolbarSample">
<uses-sdk />
<application android:label="ToolbarSample" android:theme="#style/AppTheme"></application>
</manifest>
The toolbar is like a view, so you can change his backgroundColor like this in Main.xml:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="?actionBarSize"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:background="#color/black" />
You have to define this color in file color.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Color : Classic colors -->
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
</resources>
If you really want to use android:colorPrimary.
You can create your own theme in your file styles.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat">
<!-- Value : Color -->
<item name="colorPrimary">#color/black</item>
<item name="colorAccent">#color/black</item>
</style>
</resources>
And use android:background="?attr/colorPrimary" instead.
By the way, to use this theme in all your activities, you have to declare him in your AndroidManifest.xml by adding android:theme :
<application
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Hoping this explanation is clear.
Have a nice day !

Changing background of button via Selector

I have a buttons and i want when clicked on the button, the button changed image. I think everything is ok but when clicked on the button, background button changed for one moment(while i select this) and then the background button be first background color :( What is my problem??
contact_selector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="#drawable/contactpress"></item>
<item
android:state_focused="true"
android:drawable="#drawable/contactpress"></item>
<item
android:drawable="#drawable/contact"></item>
</selector>
activity_test.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="#+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white"
android:layout_above="#id/btn"></FrameLayout>
<Button
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/contact_selector"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Thanks...
// try this
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/contactpress" android:state_pressed="true"></item>
<item android:drawable="#drawable/contactpress" android:state_focused="true"></item>
<item android:drawable="#drawable/contact" android:state_enabled="true" android:state_focused="false" android:state_pressed="false"></item>
<item android:drawable="#drawable/contactpress" android:state_enabled="false"></item>
</selector>

How to change the shape of the Textview using themes and styles?

Is there any possible ways to change the shape of the TextView using themes and styles?
I have changed textview shape as rectangle but I failed to change the hexagonal shape of textview. How could I do this?
So far tried searching the web and tried the code, but got no solution for this.
Try this code,
shape.xml ( save this in res/drawable/ )
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<corners android:radius="3dp/>
</shape>
</item>
</selector>
Then Change background of TextView.
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/shape" />
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="black_text_view_medium" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/black</item>
<item name="android:typeface">normal</item>
<item name="android:textSize">16sp</item>
</style>
</resources>
This is the resource file make in the res/values/red.xml and define this style in your textview like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
style="#style/black_text_view_medium"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is your Textview Style"
/>
</LinearLayout>

Unable to resolve color value

I am trying to make my buttons change the color of their text when it is pressed but i ran into a problem that i cant solve. I get an error saying "unable to resolve color value" then it gives me the path to the file. here are my files im using
This one is in a new folder named color under resources and its called button
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#ffff0000" />
<item android:state_focused="true" android:color="#ff0000ff" />
<item android:color="#ff000000" />
</selector>
And
<Button android:text="Main Menu" android:textColor="#color/button"
android:layout_width="200px" android:id="#+id/mainmenu"
android:layout_height="55px" android:layout_x="5dip"
android:layout_y="174dip"
android:textSize="18px">
</Button>
its driving me crazy if anybody could help me.
I successfully did it like this:
Files:
/drawable/button_states.xml
/layout/main.xml
/values/colors.xml
button_states.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#color/red" /> <!-- pressed -->
<item android:state_focused="true"
android:color="#color/blue_background" /> <!-- focused -->
<item android:color="#color/white" /> <!-- default -->
</selector>
colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="blue_background">#FF2f74c3</color>
<color name="white">#fefefe</color>
<color name="red">#ff0000</color>
</resources>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_height="wrap_content"
android:text="Button"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:textColor="#drawable/button_states" />
</LinearLayout>
Try android:background instead.

Categories

Resources