Showing errors with TextInputLayout after adding material dependency - android

I just want to know why my all TextInputLayout not applying outlined style after adding material dependency. Actually I implemented the material dependency for the badge drawable and tabmediator in my project so If delete that dependency my tablayout will crash. So, what can I do , want a solution
build.gradle
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:design:29.0.0'
implementation 'com.android.support:appcompat-v7:29.1.0'
implementation 'com.google.android.material:material:1.3.0-alpha02'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.palette:palette:1.0.0'
implementation "androidx.viewpager2:viewpager2:1.1.0-alpha01"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" 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/colorAccent</item>
<!-- <item name="android:statusBarColor">#00000000</item>-->
</style>
<style name="FullScreen" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
</resources>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jmm.rkclasses">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<application
android:name=".MyApplication"
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=".SplashActivity"
android:exported="true"
android:theme="#style/FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:theme="#style/FullScreen">
]
</activity>
</application>
</manifest>
LoginActivity.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"
android:background="#drawable/bg_login"
tools:context=".LoginActivity">
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:orientation="horizontal"
app:layout_constraintGuide_begin="32dp"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintGuide_end="24dp"
app:layout_constraintStart_toStartOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:orientation="vertical"
app:layout_constraintGuide_begin="30dp"
app:layout_constraintStart_toStartOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintGuide_end="30dp" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:fontFamily="#font/oxygen"
android:text="Welcome,"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline3"
app:layout_constraintTop_toTopOf="#+id/guideline"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/oxygen"
android:text="Log In"
android:textColor="#color/colorPrimary"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="#+id/textView"
app:layout_constraintStart_toStartOf="#+id/textView"
app:layout_constraintTop_toBottomOf="#+id/textView" />
<Spinner
android:id="#+id/spn_user_type"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="32dp"
android:background="#drawable/closed_edit_text"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="#+id/textView2"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout2"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_marginTop="8dp"
android:hint="Username"
android:paddingVertical="0dp"
app:boxStrokeColor="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="#+id/spn_user_type"
app:layout_constraintStart_toStartOf="#+id/spn_user_type"
app:layout_constraintTop_toBottomOf="#+id/spn_user_type">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="55dp"
android:layout_marginTop="8dp"
android:hint="Password"
app:layout_constraintEnd_toEndOf="#+id/textInputLayout2"
app:layout_constraintStart_toStartOf="#+id/textInputLayout2"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout2"
app:passwordToggleContentDescription="description"
app:passwordToggleDrawable="#drawable/show_password_selector"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#color/colorPrimary">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="#+id/tv_fgt_password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forget Password?"
android:textColor="#color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="#+id/textInputLayout"
app:layout_constraintTop_toBottomOf="#+id/textInputLayout" />
<Button
android:id="#+id/btn_login"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginStart="40dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="40dp"
android:background="#drawable/bg_blue_red_button"
android:fontFamily="#font/oxygen"
android:text="Log In"
android:textAllCaps="false"
android:textColor="#color/colorWhite"
android:textSize="22sp"
app:layout_constraintBottom_toTopOf="#+id/guideline2"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/guideline3"
app:layout_constraintTop_toBottomOf="#+id/tv_fgt_password"
app:layout_constraintVertical_bias="0.22000003" />
</androidx.constraintlayout.widget.ConstraintLayout>
Before changes
Before changes
After changes
After changes

You have to use a MaterialComponents theme instead of an AppCompact one.
For that, replace your style.xml file by:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<!-- <item name="android:statusBarColor">#00000000</item>-->
</style>
<style name="FullScreen" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
</resources>

You have to switch to a Material Components Theme:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- .... -->
</style>
Just a note.
Remove these dependencies since they don't exist.
//implementation 'com.android.support:design:29.0.0'
//implementation 'com.android.support:appcompat-v7:29.1.0'

Related

MaterialComponents.TextInputLayout.OutlinedBox it doesn't work properly boxBackgroundColor

I use material. I'm going to use a color for TextInputLayout for the backdrop, but something like the one below! hint background not change.i used style and wanted to make changes but it didn't work. In the layout itself I tried to apply the changes again! How to fix this problem?
NOTE
background of label username in picture that not transparent and it covers some of the TextInputEditText
in build.gradle
implementation 'com.google.android.material:material:1.1.0'
in style
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="textAppearanceSubtitle1">#style/TextAppearance.App.Subtitle1</item>
<item name="textAppearanceCaption">#style/TextAppearance.App.Caption</item>
<item name="shapeAppearanceSmallComponent">#style/ShapeAppearance.App.SmallComponent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light"/>
<style name="TextAppearance.App.Subtitle1" parent="TextAppearance.MaterialComponents.Subtitle1">
<item name="colorControlActivated">#color/white</item>
<item name="android:colorControlActivated">#color/white</item>
</style>
<style name="TextAppearance.App.Caption" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textColorTertiary">#color/white</item>
<item name="android:textColorTertiaryInverse">#color/white</item>
<item name="colorControlActivated">#color/white</item>
<item name="android:colorControlActivated">#color/white</item>
</style>
<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">16dp</item>
<item name="colorControlActivated">#color/white</item>
<item name="android:colorControlActivated">#color/white</item>
</style>
in layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#color/gray"
android:gravity="center"
android:orientation="vertical"
android:padding="32dp">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/linUsername"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:hint="#string/label_username"
android:textColorHint="#AEB0C6"
app:boxBackgroundColor="#33385E"
app:boxStrokeColor="#color/red"
app:endIconDrawable="#drawable/ic_clear_white_24dp"
app:endIconMode="password_toggle"
app:endIconTint="#AEB0C6"
app:hintTextColor="#AEB0C6"
app:startIconDrawable="#drawable/ic_info_outline_white_24dp"
app:startIconTint="#AEB0C6">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edtUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:textColor="#color/white"
android:textColorHint="#color/white"
app:hintTextColor="#AEB0C6" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/btnSelectText"
android:layout_width="168dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:fontFamily="#font/iran_sans_mobile"
android:text="login"
android:visibility="visible"
app:cornerRadius="#dimen/radiusButton" />
</LinearLayout>
You may use custom edit text with border, so you can easily set your desired background. For example try this code:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:gravity="center"
android:orientation="vertical"
android:padding="32dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:background="#drawable/boarder"
android:paddingLeft="5dp"
android:text="input"
app:endIconMode="password_toggle"
app:endIconTint="#EF0707" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="7dp"
android:background="#fff"
android:text="Label" />
</RelativeLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/btnSelectText"
android:layout_width="168dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="login"
android:visibility="visible"
app:cornerRadius="10dp" />
</LinearLayout>
boarder.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="2dp"
android:color="#03A6F0" />
<corners android:radius="12dp" />
</shape>
Also see here: Custom edit text with borders
If you don't like to use custom edit text, you can modify your code this way:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:gravity="center"
android:orientation="vertical"
android:padding="32dp">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/linUsername"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="username"
android:textColorHint="#ED0A0A"
app:boxBackgroundColor="#1A33385E"
app:endIconMode="password_toggle"
app:endIconTint="#AEB0C6">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/edtUsername"
android:background="#drawable/boarder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:textColor="#fff"
android:text="User"
android:textColorHint="#fff"
app:hintTextColor="#AEB0C6" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="#+id/btnSelectText"
android:layout_width="168dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="login"
android:visibility="visible"
app:cornerRadius="10dp" />
</LinearLayout>
And in boarder.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#8033385E"/>
<corners android:radius="12dp" />
</shape>
Output will be:

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.

Caused by: android.view.InflateException: Binary XML file line #51: Error inflating class Button

Hi my app crashes whenever i run it, i checked Logcat
and it gives this string of error
my code and the structure of my app is below , i have been looking for answer
and hope someone help me.
thanks in advance
Caused by: android.view.InflateException: Binary XML file line #51:
Error inflating class Button.
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f070063 a=-1 r=0x7f070063}
here is my XML
<?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"
tools:context=".MainActivity">
<!--tools:layout_editor_absoluteX="16dp"-->
<!--tools:layout_editor_absoluteY="81dp"-->
<android.support.constraint.ConstraintLayout
android:layout_width="135dp"
android:layout_height="203dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginTop="60dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/textView_login"
style="#style/Longin"
android:layout_width="69dp"
android:layout_height="30dp"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:text="#string/app_loging"
android:translationZ="3dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.15" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="172dp"
android:layout_height="431dp"
android:layout_marginTop="64dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/backedbackground"
style="#style/first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:background="#drawable/first"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/textView_signup"
style="#style/Longin"
android:layout_width="69dp"
android:layout_height="30dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:text="#string/app_singup"
android:textColor="#color/colorwhite"
android:translationZ="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.908"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="312dp"
android:layout_height="319dp"
android:layout_marginTop="124dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/signupfrontbackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
/>
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="62dp"
android:layout_marginTop="24dp"
android:drawableRight="#drawable/ic_user_male_black_shape"
android:ems="10"
android:hint="User name"
android:inputType="textPersonName"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="56dp"
android:drawableRight="#drawable/ic_envelope"
android:ems="10"
android:hint="#string/app_Email"
android:inputType="textEmailAddress"
android:translationZ="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.329" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="59dp"
android:layout_marginTop="140dp"
android:drawableRight="#drawable/ic_key"
android:ems="10"
android:hint="#string/app_Password"
android:inputType="textPassword"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/button2" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginTop="200dp"
android:drawableRight="#drawable/ic_key"
android:ems="10"
android:hint="#string/app_Confirm_password"
android:inputType="textPassword"
android:translationZ="2dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.505"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/button2"
/>
</android.support.constraint.ConstraintLayout>
<Button
android:id="#+id/button"
android:layout_width="128dp"
android:layout_height="38dp"
android:layout_marginBottom="44dp"
android:layout_marginEnd="116dp"
android:layout_marginRight="116dp"
android:background="#drawable/signupbutton"
android:text="#string/app_singup"
android:textColor="#color/colorwhite"
android:translationZ="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
/>
</android.support.constraint.ConstraintLayout>
my style
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<dimen name="topRightRadius">65dp</dimen>
<dimen name="textSize">20dp</dimen>
<style name="first">
<item name="android:topRightRadius">#dimen/topRightRadius</item>
<!--<item name="android:radius">65dp</item>-->
<item name="android:background">#color/colorAccent</item>
</style>
<style name="Longin">
<item name="android:textColor">#color/colorwhiteblack</item>
<item name="android:textSize">20dp</item>
</style>
</resources>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ali.myapplication">
<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"
android:theme="#style/Theme.AppCompat.DayNight.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
my string
<resources>
<string name="app_name">My Doctor</string>
<string name="app_loging">Login</string>
<string name="app_singup">Sign up</string>
<string name="app_Email">Email</string>
<string name="app_Password">Password</string>
<string name="app_Confirm_password">Confirm password</string>
</resources>
my Color
<?xml version="1.0" encoding="utf-8"?> <resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorwhite">#ffffff</color>
<color name="colortoowhite">#efe9e9</color>
<color name="colorblack">#0d0c0c</color>
<color name="colorwhiteblack">#c1baba</color>
<color name="colorharaqua">#15c5e4</color>
<color name="coloraqua">#ed1fd3e7</color>
</resources>
Structure of my app Structure of my app is below Structure of my app is below
structure
first
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape android:shape="rectangle">
<!--<corners android:topRightRadius="45dp"/>-->
<corners android:topLeftRadius="45dp"
android:topRightRadius="0.1dp"
android:bottomLeftRadius="45dp"
android:bottomRightRadius="0.1dp"/>
<gradient android:gradientRadius="45dp"
android:angle="-90" android:startColor="#5a92f0"
android:endColor="#color/colorAccent" />
</shape>
</item>
</selector>
signupfrontbackground
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape ="rectangle">
<corners android:radius="20dp"/>
<solid android:color="#color/colorwhite"/>
<stroke
android:color="#color/colortoowhite"
android:width="1dp"
/>
<!--<padding-->
<!--android:right="10dp"-->
<!--android:bottom="10dp"-->
<!--android:left="10dp"-->
<!--android:top="10dp"/>-->
</shape>
signupbutton
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#color/colorharaqua"
android:endColor="#color/coloraqua"
android:angle="360"
/>
<corners android:topLeftRadius="105dp"
android:bottomLeftRadius="105dp"
android:topRightRadius="95dp"
android:bottomRightRadius="95dp"
/>
</shape>
It is complaining about your background pointer to a non-drawable id.
android:background="#drawable/signupbutton"
Show your drawable by this name that is in the drawable directory.
Also, just a side note,
Your style "first" doesn't have a parent. You might want to try assigning a button parent to your style. Such as
<style name="first" parent="Widget.AppCompat.Button.Colored">
<item name="colorButtonNormal">#color/Red</item>
<item name="android:textColor">#color/White</item>
</style>
Just so you are tied to a specific parent of your theme instead of leaving it open, but that's just my preference.
Your drawables look fine, but they are in v24 folder, so if you're launching this on a pre-24 device, they won't be available.
I was able to reproduce your crash by setting the same folder structure and using v23 emulator.

toolbar shows in the IDE, but does not show on the emulator

I am working on an app I tried adding the back button but the toolbar does not show on the emulator again. Here is my code.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".SplashTimer"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreenActivity"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.NoActionBar" />
<activity android:name=".VerificationActivity">
<activity android:name=".MainActivity" />
</activity>
<activity android:name=".DashboardActivity" />
<activity
android:name=".LoginActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
<activity android:name=".ProblemsActivity" />
<activity
android:name=".TotalActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
<activity android:name=".FirstPayment" />
<activity android:name=".FirstPaymentInformation" />
<activity android:name=".DeclineQuestionsActivity" />
<activity android:name=".LIkelyProblemsActivity" />
<activity
android:name=".TotalAmountActivity"
android:theme="#style/Theme.AppCompat.NoActionBar" />
<activity android:name=".ThanksActivity" />
<activity
android:name=".SignUpActivity"
android:theme="#style/SignUpTheme" />
<activity android:name=".StripePayment" />
<activity
android:name=".PaymentActivity"
android:label="#string/title_activity_payment"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".LocationActivity" />
<activity android:name=".SecondPayment" />
<activity android:name=".DriverPayment"></activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
style.css
<resources>
<!-- 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>
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
<style name="SignUpTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorHint">#bdbdbd</item>
<item name="android:windowBackground">#color/colorWhite</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
myActivity
public class DashboardActivity extends AppCompatActivity {
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() == null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
public void mechanicFN (View view){
Intent intent = new Intent(DashboardActivity.this, LIkelyProblemsActivity.class); // Create an Intent
startActivity(intent); // Move to Verification Activity
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.logout){
SharedPreferences preferences = getSharedPreferences("Mypref", 0);
preferences.edit().clear().commit();
Intent intent = new Intent(DashboardActivity.this, HomeActivity.class); // Create an Intent
startActivity(intent); // Move to Verification Activity
Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
}
R.layout.activity_dashboard
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:id="#+id/activity_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/colorBackground"
tools:context="com.example.system2.tranxav.DashboardActivity">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginTop="24dp"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/cv"
android:layout_marginRight="8dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/mechanic"
android:onClick="mechanicFN"
android:id="#+id/imageView2" />
<TextView
android:text="Hire a Mechanic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView2"
android:gravity="center"
android:layout_marginBottom="16dp"
android:textColor="#000"
android:id="#+id/textView2" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
android:id="#+id/cv1"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/toyin_van"
android:id="#+id/imageView3" />
<TextView
android:text="Toyin Van"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView3"
android:gravity="center"
android:textColor="#000"
android:layout_marginBottom="16dp"
android:id="#+id/textView3" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_marginTop="24dp"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="#+id/cv3"
android:layout_marginRight="8dp"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/spareparts"
android:onClick="mechanicFN"
android:id="#+id/imageView4" />
<TextView
android:text="Spare Parts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView4"
android:gravity="center"
android:layout_marginBottom="16dp"
android:textColor="#000"
android:id="#+id/textView4" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
android:id="#+id/cv5"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content">
<ImageView
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#drawable/electrician"
android:id="#+id/imageView5" />
<TextView
android:text="Auto Electrician"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/imageView5"
android:gravity="center"
android:textColor="#000"
android:layout_marginBottom="16dp"
android:id="#+id/textView5" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
enter image description here
I browsed through the code but I cant figure out where the problem is. I have tried removing the toolbar on the activity but it did not work.
Add theme to your Activity.
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
In Manifest
<activity
android:name=".DashBoardActivity"
android:label="#string/title_activity_payment"
android:theme="#style/AppThemeNoActionBar" />
And modify onCreate() as.
if (getSupportActionBar() != null){
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}

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

Categories

Resources