I'm building an Android app and I'm wondering why some Activities show the Actionbar and some not. The actionbar itself is only showing the app package name. Two activities containing the same xml code have different behaviours. One shows the Actionbar with the app title the other one not.
The launcher activity also shows the actionbar with the app title.
Launcher Activity XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns: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=".activities.LoginActivity">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></LinearLayout>
<TextView
android:id="#+id/textpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.441" />
<TextView
android:id="#+id/textlogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.22" />
<EditText
android:id="#+id/passwordfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="9dp"
android:ems="10"
android:inputType="textPassword"
android:text="Password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textpassword" />
<EditText
android:id="#+id/loginfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textlogin" />
<Button
android:id="#+id/loginbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/passwordfield"/>
One of the two activities with strange behaviour:
<?xml version="1.0" encoding="utf-8"?>
<!-- A RecyclerView with some commonly used attributes -->
<android.support.v7.widget.RecyclerView android:id="#+id/todo_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" />
Additionally I'd like to know how to change the App title in the Acionbar. There doesn't seem to be an option inside the xml defining the title. I think android studio sets this to the project name (which is a working title by me, not the actual "real" app name)? According to the documentation I can build my own app bar (https://developer.android.com/training/appbar/setting-up). Would this help?
To create Toolbar and use a custom title in it all you need to do is remember is that Toolbar is just a fancy ViewGroup so you can add a custom title like so:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/action_bar_bkgnd"
app:theme="#style/ToolBarTheme" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:layout_gravity="center"
android:id="#+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
This means that you can style the TextView however you would like because it's just a regular TextView. So in your activity you can access the title like so:
Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
TextView mTitle = (TextView) toolbarTop.findViewById(R.id.toolbar_title);
The starange behaviour you are getting might not be that strange.
The ActionBar by default show the application name that is set in the AndroidManifest.xml as android:label="#string/app_name" .
One direct way to use a different title for your actionbar in a particular activityis to give a lable to that activity in the AndroidManifest.xm ,as follows:-
<activity android:name=".Main2Activity" android:label="page2"></activity>
This might be the reason of the starange behavior.
And if the some activities are not showing actionbar that might be becouse of the theme of the activity in the manifest file.
Related
My app has a BottomSheetDialogFragment which displays list of countries with RecyclerView. When user types in the EditText bottomsheet shrinks in size so as to wrap content. What can I do to make BottomSheet remain the same and not shrink in height. I could not find anything similar on SO, closest thing I got was this article:
https://medium.com/#oshanm1/how-to-implement-a-search-dialog-using-full-screen-bottomsheetfragment-29ceb0af3d41
Can someone explain why this shrinking happens, why the article uses 2 LinearLayouts nested inside each other and provide solution to this problem with thorough explanation?
Here is xml code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvCountry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:textSize="14sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/tilSearchCountries"
style="#style/ReBankTIL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/rtvCountry"
app:startIconDrawable="#drawable/ic_search" >
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/tieSearchCountries"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvCountries"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/tilSearchCountries" />
</androidx.constraintlayout.widget.ConstraintLayout>
i'm trying to build a layout of a ViewHolder that looks like picture 1 for a RecyclerView but instead i get some weird result, it's a project in bignerdranch 3rd version of android books and i'm sure i'm doing everything same as the book.the expected View
but instead the layout looks like my result
and this is the xml code for this layout
<?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:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/crime_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="Crime Title"
android:textColor="#color/colorAccent"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#+id/crime_solved"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/crime_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="Crime Date"
android:textColor="#color/colorAccent"
app:layout_constraintEnd_toStartOf="#+id/crime_solved"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/crime_title" />
<ImageView
android:id="#+id/crime_solved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_solved" />
If you use layout_width = 0, you should use additional property to your Views: android:layout_weight="1" that indicates the the relative width of views in parent layout. Add iy in each kid view, i think it will solve your problem.
And i don't understand why you use ConstraintLayout in such simple case, i think LinearLayout fits better here.
as you are new to android and to constraint layout ....
Here the guideline for naming convention we should follow for a long run in android . https://github.com/ribot/android-guidelines/blob/master/project_and_code_guidelines.md
As i can see hard coded text in your view , which is consider as bad practice in android . Always put your string in string file and your dimens (which is also hard code ) in dimens file . res < values < dimens .
And one surprised me alot is , why are you using orientation in constraint layout ?? Anyways i tried your view and hope this will work
<?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"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white_50"
>
<TextView
android:id="#+id/crime_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="Crime Title"
android:textColor="#color/colorAccent"
android:textSize="18sp"
app:layout_constraintEnd_toStartOf="#+id/crime_solved"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/crime_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Crime Date"
android:paddingBottom="8dp"
android:textColor="#color/colorAccent"
app:layout_constraintStart_toStartOf="#id/crime_title"
app:layout_constraintEnd_toEndOf="#id/crime_title"
app:layout_constraintTop_toBottomOf="#+id/crime_title" />
<ImageView
android:id="#+id/crime_solved"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/crime_title"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="#+id/crime_date"
app:srcCompat="#drawable/ic_solved" />
I have slight changes in the view , and removed some unnecessary code .In case of any doubt please let me know .
I'm using ConstraintLayout for the layout of a dialog fragment. It's all good except on the device with Android Lollipop. There, the layout adds up a textView(id/title) automatically on the top which is not even declared in the layout. When I run Layout Inspector, I get following results:
on Android L
on emulator with Android P
Here I fail to understand why it's happening. Here is my layout's xml code. Appreciate your help.
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#color/black_overlay"
android:layout_width="325dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvTitle"
style="#style/TextAppearance.Black"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="25dp"
android:maxLines="2"
android:text="#string/signup_alert_title"
app:layout_constraintEnd_toStartOf="#+id/ivDismissDialog"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/ivDismissDialog"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="19dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_cancel_deselected" />
<TextView
android:id="#+id/tvSignupDetails"
style="#style/TextAppearance.Regular"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="#string/signup_alert_details"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvTitle" />
<Button
android:id="#+id/signupButton"
style="#style/Button.FilledButton"
android:layout_width="208dp"
android:layout_height="wrap_content"
android:layout_marginStart="62dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="55dp"
android:text="#string/signup"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvSignupDetails" />
<Button
android:id="#+id/loginButton"
style="#style/Button.FlatButton"
android:layout_width="208dp"
android:layout_height="wrap_content"
android:layout_marginStart="62dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="55dp"
android:layout_marginBottom="24dp"
android:text="#string/login"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/signupButton" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is basically theme related. In android the root view in most cases is a FrameLayout and using a theme like Theme.AppCompat.Light.DarkActionBar can add an extra view to the ViewGroup to display an actionbar with title.
The typical default actionBar code looks like below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/title"
android:text="YOUR ACTIVITY TITLE"
android:textColor="#ffffff"
android:textSize="24sp" />
</LinearLayout>
This simply means we can access the predefined textview using a reference like below if it exists:
View decor = getWindow().getDecorView();
TextView title = (TextView) decor.findViewById(getResources().getIdentifier("title", "id", "android"));
In other to get read of the action bar or textview overall we use a different app theme that requires no action bar or we add the below options to app's parent/base theme under style:
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
In layout, TextView would be created but behind the TextView there should be some words are behind. How should I identify?
This is android studio latest version
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/roomnum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textColor="#color/colorBlack"
android:textSize="#dimen/activity_title" />
<TextView
android:id="#+id/roomtype"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="2dp"
android:textColor="#color/color_graylight"
android:textSize="#dimen/activity_title" />
</LinearLayout>
I want behind the words.
Use RelativeLayout to place two texts on top of each other. Then toggle their visibility accordingly.
For example when button is clicked:
textViewFirst.setVisibility(View.INVISIBLE)
textViewSecond.setVisibility(View.VISIBLE)
Seems the question is not very clear. I have sample code here that can help you.
<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">
<!--<RelativeLayout-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content">-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="A"
android:textSize="20sp"
android:textColor="#000"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="SAMPLE TWO"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!--</RelativeLayout>-->
</android.support.constraint.ConstraintLayout>
Sample screenshot
I have a strange feeling that your question is asking about a hint. For example:
You have a TextView and expected input is some room in a house. So the TextView will show something like "Room name", it will be in the color of light gray. If somebody types into the TextView text color will be black with his input. Am I right?
EDIT:
After your comment I am sure you are talking about Hint. There is no reson for hint in TextView it is used in EditText to let user know what is the expected input there.
<EditText
android:id="#+id/text_New_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="HERE IS YOUR HINT"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
So I have 2 activities both with a support Toolbar. The toolbar is a different color on the 2 activities so I have defined a base color (white) in the toolbar xml and then in the other activity if override the background. For some reason if I switch between the 2 activities 5 or 6 times the background of the non default activity ends up becoming the background for the other activity.
Code time:
Layout of the toolbar:
<?xml version="1.0" encoding="utf-8"?>
<!-- We use a Toolbar so that our drawer can be displayed
in front of the action bar -->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:minHeight="?attr/actionBarSize">
<!-- I have to use a custom view in order to set a custom font. -->
<TextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"/>
</android.support.v7.widget.Toolbar>
`
Login Layout (with changing toolbar color)
`
<include layout="#layout/toolbar"/>
<!--<include layout="#layout/toolbar_seam"/>-->
<RelativeLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="#+id/toolbar"
android:background="#drawable/login_gradient"/>
<TextView
android:id="#+id/company_program_label"
style="#style/basicShadow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/toolbar"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text=""
android:textColor="#FFFFFF"
android:textSize="24sp"/>
<RelativeLayout
android:id="#+id/platform_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/company_program_label"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="6dp">
<RelativeLayout
android:id="#+id/username_input_wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/login_field_top"
>
<EditText
android:id="#+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="5dp"
android:layout_toLeftOf="#+id/save_username"
android:layout_toStartOf="#+id/save_username"
android:background="#FFFFFF"
android:hint="#string/login_username_hint"
android:inputType="text"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:singleLine="true"
android:textSize="16sp"
/>
<!--android:background="#FFFFFF"-->
<ImageButton
android:id="#+id/save_username"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/username"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/username"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:padding="12dp"
android:scaleType="centerInside"
android:src="#drawable/pin_up"
/>
</RelativeLayout>
<RelativeLayout
android:id="#+id/password_input_wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/username_input_wrapper"
android:background="#drawable/login_field"
>
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="5dp"
android:layout_toLeftOf="#+id/show_password"
android:layout_toStartOf="#+id/show_password"
android:background="#FFFFFF"
android:hint="#string/login_password_hint"
android:inputType="textPassword"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:singleLine="true"
android:textSize="16sp"
/>
<ImageButton
android:id="#+id/show_password"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/password"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/password"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:padding="12dp"
android:scaleType="centerInside"
android:src="#drawable/eye_closed"
/>
</RelativeLayout>
<Button
android:id="#+id/login_button"
style="#style/basic_button_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/password_input_wrapper"
android:background="#drawable/login_button"
android:enabled="false"
android:text="#string/login_login_button"
/>
</RelativeLayout>
<TextView
android:id="#+id/terms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/platform_wrapper"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="#string/login_terms_and_policy"
android:textSize="11sp"
/>
<Button
android:id="#+id/forgot_button"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_below="#+id/terms"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#66000000"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="#string/login_forgot_button"
android:textColor="#66FFFFFF"
android:textSize="12sp"
android:visibility="visible"
/>
</RelativeLayout>
</LinearLayout>
other layout (which should have the default toolbar color)
<include layout="#layout/toolbar"/>
<include layout="#layout/toolbar_seam"/>
<FrameLayout
android:id="#+id/webview_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/debug_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
</LinearLayout>
In the login activity I have the following code to change the toolbar background color:
protected void themeToolbar()
{
super.themeToolbar();
this.navigationBack();
this.titleBlank();
this.toolbar.setBackgroundColor(Color.RED);
}
In order to transition between the activities I have a textview with a custom schema that triggers the other intent via LinkMovementMethod
terms = (TextView) this.findViewById(R.id.terms);
terms.setMovementMethod(LinkMovementMethod.getInstance());
The first couple of times i transition to and from the other activity everything is fine but after about 6 times the entire background of the other activity changes to the color set in this.toolbar.setBackgroundColor(Color.RED); which is really weird because the toolbar doesn't cover the entire page. What is even worse is that views that used to be white on the login activity now show up red.
My best guess is that there is some kind of shared ColorDrawable using for all white backgrounds and that it is being overridden with the the red color but I have no idea why.
Login as it should be:
Other activity as it should be:
Other activity after switching back and forth 6 times:
Login activity after other activity screws up:
Yes, Android shares the background drawable in activities with the same Theme. So create a new Drawable if you want to explicit set it:
setBackground(new ColorDrawable(Color.RED))
Use different styles for the toolbar instead changing the background explicitly. The color of the toolbar will be per activity, you can use whatever color you want.
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<!-- For transparent toolbar -->
<style name="AppTheme.AppBarOverlay.Transparent" parent="AppTheme.AppBarOverlay" >
<item name="android:background">#color/transparent</item>
</style>
Now just set the style of the toolbar.
Regular Toolbar
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/AppTheme.AppBarOverlay" />
Transparent Toolbar
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/AppTheme.AppBarOverlay.Transparent" />