CheckBox colour not changing - android

I have a CheckBox and I don't know how to change its colours.
I tried creating a custom style in styles.xml and styles21.xml
I added there:
<style name="checkBoxStyle" parent="Base.Theme.AppCompat">
<item name="colorAccent">#color/white100</item>
<item name="android:textColorSecondary">#color/white87</item>
</style>
then I added the style to my CheckBox, as:
#style/checkBoxStyle
No change in the colour. Its still black and I want it white.
Tried creating another checkbox, cuz I taught I might have messed the previous one. Same result.
manifest:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".InputTaskActivity"
android:windowSoftInputMode="stateVisible">
</activity>
</application>
XML with the checkbox inside:
<?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="55dp"
android:layout_margin="5dp"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="1">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="TextView"
android:textColor="#color/white100"
android:textSize="18sp" />
<Space
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<CheckBox
android:id="#+id/checkBox3"
style="#style/checkBoxStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>

Change the style attribute to theme as follows:
<CheckBox
android:id="#+id/checkBox3"
android:theme="#style/checkBoxStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

You might have to create a new theme with the new accent color. Then you have to specify the newly created theme in the manifest for the activity your checkbox is located in.

CheckBox style in res/values/styles
<style name="MyCheckBox" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">#color/colorGreen</item>
<item name="colorControlActivated">#color/colorBlue</item>
</style>
res/values/colors.xml
<color name="colorBlue">#022ce6</color>
<color name="colorGreen">#02e602</color>
in your actvitiy XML file
<CheckBox
android:id="#+id/checkBox3"
android:theme="#style/MyCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />

Related

The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)

i am new to Android and i might have a silly / dumb Question. I have got an Activity where i want to dynamically create Multiple Input Fields. The amount of Input Fields is defined by the User.
Because the Input is Styled and Consists of 2 Elements and didnt want to Create these Elements every Time because of Elements have got multiple Parameters that are the same every time. Thats why i created a XML File just for this two Elements which i would like to use in my Programm to Create the Inputs.
View_input.xml
<?xml version="1.0" encoding="utf-8"?>
<merge 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"
android:orientation="vertical"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayoutTableName"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="10dp"
android:hint="#string/create_table_name"
android:inputType="text"
app:boxStrokeColor="#color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:placeholderText="#string/create_table_table_name_placeholder"
app:startIconTintMode="src_in">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textInputName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="" />
</com.google.android.material.textfield.TextInputLayout>
</merge>
My Target XML (activity_create_table_column_names.xml) looks like this:
<?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=".ui.createtable.CreateTableColumnNamesActivity">
<LinearLayout
android:id="#+id/columnNameInputContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="start"
android:orientation="vertical"
android:padding="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/create_table_column_names"
android:textStyle="bold" />
<!-- HERE -->
</LinearLayout>
Where i wrote <!-- HERE -->i want all my Input-Fields to be.
I started with just displaying one Input:
private fun initLayout() {
val container = findViewById<LinearLayout>(R.id.columnNameInputContainer)
val inflater = applicationContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(R.layout.view_input, LinearLayout(this))
container.addView(view)
}
But i got the Following Exception:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:115)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:458)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:417)
My Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
...
</style>
</resources>
What am i doing wrong? Is this even the correct way i should programm something like this?
Edit:
Android.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="de.hsos.ma.adhocdb">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:appComponentFactory="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:appComponentFactory">
<activity
android:name=".ui.createtable.CreateTableColumnNamesActivity"
android:parentActivityName=".ui.homescreen.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.createtable.CreateTableActivity"
android:parentActivityName=".ui.homescreen.MainActivity" />
<activity
android:name=".ui.homescreen.TestTableActivity"
android:parentActivityName=".ui.homescreen.MainActivity">
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity
android:name=".ui.TableShow.TableShowActivity"
android:parentActivityName=".ui.homescreen.MainActivity" />
<activity android:name=".ui.tablelist.LayoutTableListItem" />
<activity android:name=".ui.homescreen.MainActivity">
</activity>
</application>
</manifest>
found the solution ,get your inflator from activity not application just modify your initLayout() like this
// here is the fix
val inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
just set the theme on the chip itself using android:theme="#style/Theme.MaterialComponents.Bridge:
<com.google.android.material.chip.Chip
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:theme="#style/Theme.MaterialComponents.Bridge"****
style="#style/CustomFiltersChipChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:chipStrokeColor="#F0F"
app:chipStrokeWidth="1dp"
app:textEndPadding="10dp"
app:textStartPadding="10dp"
tools:chipText="my chip"
tools:text="Fortune" />
If you don't want your view to change and with on tool bar try this,
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge"/>

Why does my app not fill the entire screen?

Here I have 2 screenshots
The top one is my app. The 2nd one is facebook. Notice how facebook takes up the entire screen while mine is just short of reaching the top and bottom. How can I get my app to fill the entire screen, or atleast have it extend to right under the time and battery percentage?
Styles XML file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorBlack</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textAllCaps">false</item>
<item name="navigationViewStyle">#style/Widget.Design.NavigationView</item>
</style>
<style name="AppTheme.ActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">false</item>
<item name="android:textColorSecondary">#color/colorWhite</item>
<item name="android:textColorPrimary">#color/colorWhite</item>
</style>
Layout XML file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">
<ImageView
android:id="#+id/btnApply"
android:layout_width="0dp"
android:layout_height="50dp"
android:contentDescription="#null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#color/colorPrimary" />
<TextView
android:id="#+id/txtApplyButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="#null"
android:gravity="center_horizontal"
android:text="APPLY"
android:textColor="#color/colorWhite"
app:fontFamily="#font/varela"
app:layout_constraintBottom_toBottomOf="#+id/btnApply"
app:layout_constraintEnd_toEndOf="#+id/btnApply"
app:layout_constraintStart_toStartOf="#+id/btnApply"
app:layout_constraintTop_toTopOf="#+id/btnApply" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
android:id="#+id/txtFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:ems="10"
android:hint="#string/first_name"
android:inputType="textPersonName"
android:maxLength="30"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/txtLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:ems="10"
android:hint="#string/last_name"
android:inputType="textPersonName"
android:maxLength="30"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/linearLayout">
<TextView
android:id="#+id/txtLocation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:text="Locations"
android:textColor="#color/colorGray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#+id/txtLocation">
<ImageView
android:id="#+id/btnAddLocation"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:contentDescription="#null"
app:srcCompat="#drawable/ic_add_black_24dp" />
<ImageView
android:id="#+id/btnRemoveLocation"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:contentDescription="#null"
app:srcCompat="#drawable/ic_delete_black_24dp" />
<Spinner
android:id="#+id/spnrLocations"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp">
<ImageView
android:id="#+id/imgVerified"
android:layout_width="30dp"
android:layout_height="30dp"
android:contentDescription="#null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/txtVerified"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:fontFamily="#font/varela"
android:textColor="#color/colorGreen"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#+id/imgVerified"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</ScrollView>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:icon="#drawable/ic_home_black_24dp">
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".EmailSignUp" />
<activity android:name=".EmailVerification" />
<activity android:name=".EmailSignIn" />
<activity android:name=".Home" />
<activity android:name=".AddLocation" />
<activity android:name=".InstantMessage" />
<activity android:name=".ProcessPayment" />
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
</application>
Use this one theme
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textAllCaps">false</item>
</style>
You can do this programmatically
You need to set up
getWindow().getDecorView().setSystemUiVisibility(flag);
Setup these flags inside onWindowFocusChanged of your activity (onWindowFocusChanged
mainly used for fullscreen so you can retain your fullscreen even after focus change. you can also set flags in your onCreate or where you like)
in your activity you can do like
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//You can also pass multiple flags as i did. one for hide navigation one for make layout stable
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
}
}
}
For Extra there is also other flags that change system ui like flag for fullscreen.
here you can find all flags. just search for system_ui_flag
I woke up this morning, tried running it again, and everything looked fine. I changed absolutely nothing. Android studio/my phone must have a mind of it's own.

2 almost identical activities in 2 projects, but 1 doesn't have toolbar

When I normally create a new project, the activities have toolbars on top like this:
But somehow, I'm a noob so I managed to somehow delete this action bar by modifying the styles xml the Activity and the manifest. So now it's a fullscreen activity, even when I use DarkActionBar as parent in styles:
Here my files:
Styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swagdev.app.swagpoints">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Map"/>
</application>
Activity:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.swagdev.app.swagpoints.MainActivity">
<com.journeyapps.barcodescanner.BarcodeView
android:layout_width="300dp"
android:layout_height="300dp"
app:zxing_use_texture_view="true"
android:id="#+id/scanner"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/location_field"
android:textSize="30sp"
android:layout_below="#+id/scanner"
android:layout_centerHorizontal="true"
android:layout_marginTop="45dp" />
<TextView
android:text="Scan Sticker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tvh"
android:textSize="30sp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" />
<nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="content"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tag="menu"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</FrameLayout>
</nl.psdcompany.duonavigationdrawer.views.DuoDrawerLayout>
</RelativeLayout>
SO now my toolbar is gone. How do i need to modify styles or activity or manifest to get it back?

How can I theme my action bar to match this image?

I'm working on an app's UI and I want to get the action bar to look like this:
This is what it looks like right now:
This is my styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/sunshine_blue</item>
<item name="colorPrimaryDark">#color/sunshine_dark_blue</item>
</style>
<!-- Main activity theme -->
<style name="ForecastTheme" parent="AppTheme">
<item name="actionBarStyle">#style/ActionBar.Solid.Sunshine.NoTitle</item>
</style>
<!-- Detail activity theme -->
<style name="DetailTheme" parent="AppTheme">
<item name="actionBarStyle">#style/ActionBar.Solid.Sunshine.Title</item>
</style>
<!-- Settings activity theme -->
<style name="SettingsTheme" parent="AppTheme">
</style>
<!-- Main activity action bar styles -->
<style name="ActionBar.Solid.Sunshine.NoTitle" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#drawable/ic_logo</item>
</style>
<!-- Detail activity action bar styles -->
<style name="ActionBar.Solid.Sunshine.Title" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">#drawable/art_clear</item>
</style>
<!-- style for item selected on phone -->
<style name="ForecastListStyle">
<item name="android:choiceMode">none</item>
</style>
</resources>
This is the layout file for my detail activity:
<!-- Master layout -->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textSize="24sp"
android:id="#+id/detail_day_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:textSize="16sp"
android:textColor="#color/fragment_detail_grey"
android:id="#+id/detail_date_textview" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="96sp"
android:paddingStart="32dp"
android:paddingLeft="32dp"
android:id="#+id/detail_high_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="48sp"
android:textColor="#color/fragment_detail_grey"
android:paddingStart="64dp"
android:paddingLeft="64dp"
android:id="#+id/detail_low_textview" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/detail_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="22sp"
android:textColor="#color/fragment_detail_grey"
android:id="#+id/detail_forecast_textview" />
</LinearLayout>
</LinearLayout>
<!-- Humidity, wind, pressure -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_humidity_textview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_pressure_textview" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="22sp"
android:layout_margin="2dp"
android:id="#+id/detail_wind_textview" />
</LinearLayout>
</ScrollView>
And this is my AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.sunshine.app" >
<!-- This permission is necessary in order for Sunshine to perform network access. -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:theme="#style/ForecastTheme"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DetailActivity"
android:theme="#style/DetailTheme"
android:label="#string/title_activity_detail"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.sunshine.app.MainActivity" />
</activity>
<activity
android:name=".SettingsActivity"
android:label="#string/title_activity_settings"
android:theme="#style/SettingsTheme"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.sunshine.app.MainActivity" />
</activity>
<provider
android:authorities="com.example.android.sunshine.app"
android:name=".data.WeatherProvider" >
</provider>
</application>
</manifest>
I've tried a couple different things in the displayOptions but can't seem to get the logo and "Details" text to display at the same time. Also, is there any way to get the arrow to match? Or does this just depend on the API level?
Thanks for any help!
It's better to use menu item in toolbar/app bar.
in this way there will be no additional space or any dislocate item in action bar .
<menu 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"
tools:context=".MainActivity">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:orderInCategory="100"
android:title="#string/action_share"
app:showAsAction="always" />
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_action_share"
android:orderInCategory="101"
android:title="#string/action_search"
app:showAsAction="always" />
<item
android:id="#+id/action_settings"
android:orderInCategory="102"
android:title="#string/action_settings"
app:showAsAction="never" /> </menu>
And just remember using toolbar is much more easier for your purpose
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/ColorPrimary"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
Here's complete tutorial

Android custom style/scheme is not applied correctly to button-textColor

I'm having trouble with applying a custom scheme(style) to certain views. I have defined my own style in res/values/styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="myStyle1">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/red</item>
<item name="android:textColorHighlight">#color/blue</item>
<item name="android:textColorHint"> #color/fuchsia</item>
<item name="android:textColorLink">#color/olive</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme" parent="android:Theme.Light" />
</resources>
I have applied this style to the main activity of my simple test application, like this
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/myStyle1" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
.
.
</application>
The layout of the MainActivity contains a couple of buttons, some textViews, some of them have the style attribute spiecified explicitly, others should be inhertiting it from the whole activity.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/silver"
android:orientation="vertical" >
<EditText android:id="#+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:hint="#string/edit_message" />
<Button android:id="#+id/send_button"
style="#style/myStyle1"
android:text="#string/button_send" />
<Button android:id="#+id/relative_activity"
android:text="#string/rel_activitity_text"
android:onClick="startRelativeActivity"/>
<Button android:id="#+id/button_TTT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textColor="#color/red"
android:text="#string/button_TTT" />
<fragment android:name="my.firstapp.Fragment1"
android:background="#color/red"
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
As far as I can tell, everything in the activity should be stylized according to the style I ahve defined, however, this is what I get
As you can see, only the buttons with the specified style have their text in red, the other two don't. However, even the white buttons get the correct font from the scheme, so at least some of it is being applied. Why not all of it? Any help would be appreciated, I'm thoroughly confused.
If you want a global style for all your buttons you need to do something like this.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="myStyle1">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/red</item>
<item name="android:textColorHighlight">#color/blue</item>
<item name="android:textColorHint"> #color/fuchsia</item>
<item name="android:textColorLink">#color/olive</item>
<item name="android:typeface">serif</item>
</style>
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:buttonStyle">#style/myStyle1</item>
</style>
</resources>
In your android manifest you should set the theme...
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
.
.
.
</application>
You can do the same thing for checkboxs etc. More information from this link.
http://developer.android.com/reference/android/R.attr.html
Also I tested this on the following layout. All 3 buttons should have red text.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffaaaaaa"
android:orientation="vertical" >
<EditText android:id="#+id/edit_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:hint="edit_message" />
<Button android:id="#+id/send_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button_send" />
<Button android:id="#+id/relative_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="rel_activitity_text"
android:onClick="startRelativeActivity"/>
<Button android:id="#+id/button_TTT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textColor="#ffff0000"
android:text="button_TTT" />
<!--<fragment android:name="my.firstapp.Fragment1"
android:background="#00ff0000"
android:id="#+id/list"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />-->
</LinearLayout>

Categories

Resources