Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit a929950

Browse files
committed
Add Activity.contentView property #157
1 parent f2a521e commit a929950

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

anko/library/static/common/src/ContextUtils.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import android.os.Bundle
2626
import android.os.Parcelable
2727
import android.preference.PreferenceManager
2828
import android.view.View
29+
import android.view.ViewGroup
2930
import org.jetbrains.anko.internals.AnkoInternals.NoBinding
3031
import java.io.Serializable
3132

@@ -56,6 +57,12 @@ val Context.ctx: Context
5657
val Activity.act: Activity
5758
get() = this
5859

60+
/**
61+
* Returns the content view of this Activity if set, null otherwise.
62+
*/
63+
val Activity.contentView: View?
64+
get() = findOptional<ViewGroup>(android.R.id.content)?.getChildAt(0)
65+
5966
inline fun <reified T : View> View.find(id: Int): T = findViewById(id) as T
6067
inline fun <reified T : View> Activity.find(id: Int): T = findViewById(id) as T
6168
inline fun <reified T : View> Fragment.find(id: Int): T = view?.findViewById(id) as T

0 commit comments

Comments
 (0)