Change BaseActivity' Toolbar Title From Child Activity - android

I have a BaseActivity which gets inherited from all the other child activities and in that BaseActivity I set the toolbar:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(getLayoutId())
if (toolbar != null) {
setSupportActionBar(toolbar)
supportActionBar?.apply {
setDisplayShowTitleEnabled(getActivityTitle() != null)
setDisplayHomeAsUpEnabled(getActivityTitle() != null)
getActivityTitle()?.let {
this.title = getActivityTitle()
}
}
}
}
open fun getActivityTitle(): String? = null
And on the ChildActitivy I have the following code:
override fun getActivityTitle(): String? {
return getString(R.string.gen_everyone_is_watching)
}
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
<ImageView
android:id="#+id/toolbar_logo"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_logo" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
The problem is that I can not display the title when I want to do that in a child activity and the only way I have found to display the title is to not set the toolbar on the BaseActivity. Have you encountered anything similar?

Related

Title overlaps with view in custom toolbar Android

Hey guys I am trying to set title in my custom toolbar. It's not working until I explicit through xml. I don't want to put a Textview in xml in toolbar. I tried this post and trying to set by code, it is not working.
consultation.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:focusable="true">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="150dp"
android:backgroundTint="#FFC04A"
android:fitsSystemWindows="true"
android:gravity="bottom">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<androidx.appcompat.widget.SearchView
android:id="#+id/consultationSearchView"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="#drawable/consultations_search_edit_text_rounded_corner"
android:fitsSystemWindows="true"
android:theme="#style/ConsultationsSearchViewTheme"
app:layout_collapseMode="pin" />
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_collapseMode="pin"
app:titleTextColor="#android:color/white" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I tried through code
ToolbarActivity.kt
class ToolbarActivity : AppCompatActivity() {
private lateinit var binding: ToolBarLayoutBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ToolBarLayoutBinding.inflate(layoutInflater)
setContentView(binding.root)
actionBar()
setupSearchView()
}
private fun actionBar() {
setSupportActionBar(binding.toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowTitleEnabled(true)
supportActionBar?.title = "Toolbar"
}
private fun setupSearchView() {
var originalMargin = 0
binding.consultationSearchView.apply {
setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?) = false
override fun onQueryTextChange(newText: String?): Boolean {
if (newText != null) {
}
return true
}
})
val params =
binding.consultationSearchView.layoutParams as CollapsingToolbarLayout.LayoutParams
originalMargin = params.marginStart
setOnQueryTextFocusChangeListener { view, hasFocus ->
binding.appBar.setExpanded(!hasFocus)
isSelected = hasFocus
if (hasFocus) {
params.marginStart = originalMargin + 150 // arbitrary constant
} else {
params.marginStart = originalMargin
}
view.layoutParams = params
}
}
}
}
It look like this
Note I don't want to use xml to set text view inside toolbar. I want to do it programmatically. Inside my github project I used xml text view.
Expected output
when screen opens i want like this arrow + title
when collapse it look like this

Fragment replaced in activity does not show setDisplayHomeAsUpEnabled arrow

In my activity I have one FrameLayout that needs to be swapped out with another fragment on button press. When the second fragment is pushed, the actionbar does not show the back arrow. However, pressing the back triangle does pop the second fragment and returns to the Main Fragment.
The initial Activity with the Main fragment
You can see that the second fragment is added, but the arrow is not present to take the user back. Even though in my NewCallFragment I have the line
activity?.actionBar?.setDisplayHomeAsUpEnabled(true)
What am I doing wrong?
My Activity
private const val TAG = "DashboardActivity"
class DashboardActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dashboard)
if (savedInstanceState == null) {
supportFragmentManager.commit { add<MainFragment>(R.id.fragment_container, null, intent.extras) }
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putCharSequence(TAG, title)
}
override fun onSupportNavigateUp(): Boolean {
if (supportFragmentManager.popBackStackImmediate()) {
return true
}
return super.onSupportNavigateUp()
}
class MainFragment : Fragment(R.layout.fragment_dashboard_main) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<Button>(R.id.btnNewCall).setOnClickListener {
onShowNewCall()
}
}
private fun onShowNewCall() {
activity?.supportFragmentManager?.commit {
replace<NewCallFragment>(R.id.fragment_container, null, null)
addToBackStack(null)
}
}
}
class NewCallFragment : Fragment(R.layout.fragment_new_call) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity?.actionBar?.setDisplayHomeAsUpEnabled(true)
activity?.title = "My Second Fragment"
}
}
}
Activity Layout
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/dashboard_root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="#dimen/parent_padding"
tools:context=".activitiesx.DashboardActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Main Fragment Layout
<RelativeLayout 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">
<com.google.android.material.button.MaterialButton
android:id="#+id/btnNewCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp"
android:paddingTop="10sp"
android:paddingBottom="10sp"
android:text="#string/new_call"
app:icon="#drawable/ic_add" />
</RelativeLayout>
New Call Fragment Layout
<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/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add new call"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Toolbar appearing blank on android activity

My toolbar on top of my activity appears blank but it should have a navigation custom icon and a title but neither is visible?
Here is my xml
<androidx.coordinatorlayout.widget.CoordinatorLayout 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/white">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:minHeight="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay" />
here is my activity
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_me)
setupToolbar()
}
private fun setupToolbar() {
setSupportActionBar(toolbar)
toolbar.setNavigationIcon(R.drawable.ic_close)
toolbar.setNavigationOnClickListener {
onBackPressed()
}
toolbar.setTitle(R.string.profile_unfollow_warning)
supportActionBar!!.setHomeButtonEnabled(true)
supportActionBar!!.setDisplayShowCustomEnabled(true)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
supportActionBar!!.show()
}
}
Theme i am using for this activity
<activity android:name=".ui.profile.MyActivity"
android:label="#string/app_name"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="#style/Theme.MaterialComponents.NoActionBar"/>
public class MainActivity {
// Declaring the Toolbar Object
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
// Attaching the layout to the toolbar object
toolbar = (Toolbar) findViewById(R.id.tool_bar);
// Setting toolbar as the ActionBar with setSupportActionBar() call
setSupportActionBar(toolbar);
}
Create a xml file like tool_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:elevation="4dp" />
Include the Toolbar into your main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar" />
<TextView
android:layout_below="#+id/tool_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/TextDimTop"
android:text="#string/hello_world" />
</RelativeLayout>
Opps, It seems to be a bug in ordering
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setTitle(R.string.profile_unfollow_warning)
supportActionBar?.setHomeButtonEnabled(true)
supportActionBar?.setDisplayShowCustomEnabled(true)
toolbar?.setNavigationIcon(R.drawable.ic_close)
toolbar?.setNavigationOnClickListener {
onBackPressed()
}

NavigationDrawer not appearing with AndroidX

I have an app that I am using with androidx components and I cannot get it to show the hamburger icon indicating a DrawerActivity. Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
android:id="#+id/drawer_layout"
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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
tools:context=".MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
style="#style/Widget.MyApp.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/Base.ThemeOverlay.AppCompat.Dark"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/sliding_tabs"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<com.webnation.begonerobotexters.widgets.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
app:layout_constraintBottom_toTopOf="#+id/viewpager"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewpager"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/sliding_tabs"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- The navigation drawer -->
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemIconTint="#android:color/white"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/menu_drawer"/>
</androidx.drawerlayout.widget.DrawerLayout>
Here is how I am setting up navigation drawer in the activity:
private fun setUpNavigationDrawer() {
setSupportActionBar(toolbar)
val actionBar = supportActionBar
try {
assert(actionBar != null)
actionBar?.setDisplayHomeAsUpEnabled(true)
actionBar?.setHomeButtonEnabled(true)
//actionBar?.setSubtitle(getString(R.string.subtitle))
actionBar?.setDisplayShowTitleEnabled(true)
} catch (ignored: Exception) {
Timber.e(ignored)
ignored.printStackTrace()
}
toolbar?.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary))
toolbar?.setTitleTextColor(ContextCompat.getColor(this, R.color.tab_text_color))
navigation_view.setNavigationItemSelectedListener { menuItem ->
menuItem.isChecked = true
when (menuItem.itemId) {
R.id.navigation_item_1 -> {
val intent = Intent(this, EulaActivity::class.java)
intent.putExtra(keyFileName, "privacy")
startActivity(intent)
}
R.id.navigation_item_2 -> {
val intent = Intent(this, EulaActivity::class.java)
intent.putExtra(keyFileName, "eula")
startActivity(intent)
}
R.id.navigation_item_3 -> {
}
}
if (navigation_view != null) {
drawer_layout?.closeDrawer(navigation_view)
}
true
}
mDrawerToggle = object: ActionBarDrawerToggle(this, drawer_layout, toolbar,R.string.drawer_open, R.string.drawer_close) {
override fun onDrawerOpened(drawerView: View) {
super.onDrawerOpened(drawerView)
invalidateOptionsMenu()
}
override fun onDrawerClosed(view: View) {
super.onDrawerClosed(view)
//getSupportActionBar().setTitle(mActivityTitle);
invalidateOptionsMenu()
}
}
mDrawerToggle.isDrawerIndicatorEnabled = true
drawer_layout?.addDrawerListener(mDrawerToggle)
mDrawerToggle.syncState()
}
Here is my DrawActivity:
class DrawerActivity : AppCompatActivity() {
lateinit var draw_layout: DrawerLayout
lateinit var mDrawerToggle: ActionBarDrawerToggle
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onStart() {
super.onStart()
draw_layout = findViewById<DrawerLayout>(R.id.drawer_layout)
mDrawerToggle = ActionBarDrawerToggle(this, draw_layout, 0, 0)
draw_layout.addDrawerListener(mDrawerToggle)
val actionBar = supportActionBar
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true)
actionBar.setDisplayShowHomeEnabled(true)
actionBar.setDisplayShowTitleEnabled(true)
actionBar.setDisplayUseLogoEnabled(false)
actionBar.setHomeButtonEnabled(true)
}
}
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
mDrawerToggle.syncState()
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item)
}
}
What am I doing wrong?
ActionBarDrawerToggle is deprecated for quite a while; one can use the framework's own resId for that button (to be inflated into the ActionBar's custom view - so that it will appear where it should):
<androidx.appcompat.widget.AppCompatImageButton
android:id="#android:id/home"
android:src="#drawable/ic_menu_black_36dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#null" />
The one can get the click event along with top-right menu events; for example:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
/* hide/show NavigationView */
break;
...
}
}
I found out my viewpager/sliding bar tab was covering the action bar. So I switched out my ConstraintLayout for a LinearLayout, and poof it appeared.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:orientation="vertical"
tools:showIn="#layout/activity_main"
tools:context=".MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
style="#style/Widget.MyApp.ActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="#style/Base.ThemeOverlay.AppCompat.Dark"
/>
<com.webnation.begonerobotexters.widgets.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
/>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewpager"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
</LinearLayout>
<!-- The navigation drawer -->
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemIconTint="#android:color/white"
app:headerLayout="#layout/drawer_header"
app:menu="#menu/menu_drawer"/>
</androidx.drawerlayout.widget.DrawerLayout>

How to retain state of views of orientation changes in Android Conductor?

I am currently learning about the Conductor framework for Android and have a bit of a problem or misunderstanding of how it works.
I was under the impression that the method
setRetainViewMode(RetainViewMode.RETAIN_DETACH);
would save the states of the views in the controller. To test the behaviour, I added EditText views, entered a value in it and rotated the screen. I also added 2 views with onclick listeners attached, changing the background color onclick
The result of the test was that the EditText views maintained the state and preserved the entered values. But the 2 views, changed back to their original background color (none).
This is the behaviour of the views regardless on which RetainViewMode is set
I have this simple MainActivity (note: I'm writing in Kotlin):
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var router: Router = Conductor.attachRouter(this, controller_container, savedInstanceState)
if (!router.hasRootController()) {
var t : TestController = TestController()
t.retainViewMode = Controller.RetainViewMode.RETAIN_DETACH
router.setRoot(RouterTransaction.with(t))
}
}
companion object doTask {
fun start(activity : Activity) {
val intent = Intent(activity, MainActivity::class.java)
activity.startActivity(intent)
}
}
}
And here is the the TestController:
class TestController : BaseController() {
var i : Int = 0
var h : Int = 0
override fun onViewBound(view: View) {
view.a.setOnClickListener {
i++
if (i % 2 == 0) {
view.a.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.white))
} else {
view.a.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.turtle_green))
}
}
view.b.setOnClickListener {
h++
if (h % 2 == 0) {
view.b.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.white))
} else {
view.b.setBackgroundColor(ContextCompat.getColor(applicationContext, R.color.blue_light))
}
}
}
override fun inflateView(inflater: LayoutInflater, container: ViewGroup): View {
return inflater.inflate(R.layout.controller_layout_test, container, false)
}
}
And xml layout file controller_layout_test:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<requestFocus></requestFocus>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/logo_simple"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="300dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="30dp"
android:layout_gravity="center"
android:background="#color/transparent50p"
android:padding="20dp">
<EditText
android:id="#+id/gt"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:padding="6dp"
android:background="#color/white_transparent50p"/>
/>
<EditText
android:id="#+id/erergeargf"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:padding="6dp"
android:background="#color/white_transparent50p"/>
<View
android:id="#+id/a"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:layout_gravity="center"></View>
<View
android:id="#+id/b"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:layout_gravity="center"></View>
</LinearLayout>
</ScrollView>
</FrameLayout>
activity_main xml layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="dk.minreklame.minetilbud_v2.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
</android.support.design.widget.AppBarLayout>
<com.bluelinelabs.conductor.ChangeHandlerFrameLayout
android:id="#+id/controller_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
As your views have references to the host Activity, they will never be retained across orientation changes. That would cause a memory leak. The docs on RETAIN_DETACH state:
The Controller will retain its reference to its view when detached, but will still release the reference when a config change occurs.

Categories

Resources