Operator | Instead Function | Example |
---|---|---|
& | and | 1.and(1) |
| | or | 1.or(1) |
^ | xor | 1.xor(1) |
~ | inv | 1.inv(1) |
android:layout_marginRight="?android:attr/actionBarSize"
OR
android:layout_marginEnd="?android:attr/actionBarSize"
<android.support.v7.widget.Toolbar
android:id="@+id/custom_toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@android:color/holo_red_dark">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="abc"
android:textColor="@android:color/white"
android:textSize="20sp"
android:layout_marginRight="?android:attr/actionBarSize"
android:gravity="center"/>
</android.support.v7.widget.Toolbar>
var x = 1
var y = 5
println("x AND y = ${x and y}")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val PREFS_NAME = "MyPrefsFile"
val settings = getSharedPreferences(PREFS_NAME, 0)
if (settings.getBoolean("my_first_time", true)) {
// First launched
settings.edit().putBoolean("my_first_time", false).commit()
} else {
// Other
}
}
var result = ""
val data = arrayOf("1", "2", "3", "4", "5")
run loop@{
data.forEachIndexed { index, string ->
if (index == 3) {
result = string
return@loop
}
}
}
print(result)
println(java.lang.String.format("%s, %s, %6f : %3f", "A", "B", 3.0, 4.0))
Layout XML Name : activity_basic.xml
class YourActivity : BaseActivity() {
lateinit var mBinding: ActivityBasicBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_basic)
}
}
var layoutInflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
var containedView = /* Use this */ mBinding.itemsContainedView /* Use this */
var mExampleBinding = DataBindingUtil.inflate(layoutInflater, R.layout.layout_example, containedView, false)
mExampleBinding.tvView.setOnClickListener { v ->
Toast.makeText(mActivity, "Hello World", Toast.LENGTH_SHORT).show()
}
val email = Intent(Intent.ACTION_SEND)
email.type = "plain/text"
email.putExtra(Intent.EXTRA_EMAIL, arrayOf("example@domain.com"))
email.putExtra(Intent.EXTRA_SUBJECT, "subject")
email.putExtra(Intent.EXTRA_TEXT, "content")
startActivity(email)
class YourFragment : BaseFragment() {
lateinit var mBinding: YourFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_basic, container, false)
return mBinding
}
}
((activity as YourActivity).getFragment() as YourFragment).fragmentFinish()
var imageDrawable = R.drawable.image
mBinding.element.setImageDrawable(
ContextCompat.getDrawable(
mActivity,
imageDrawable
)
)
mBinding.element.setImageDrawable(
getDrawable(
mActivity,
R.drawable.image
)
)
var requestOptions = RequestOptions()
requestOptions = requestOptions.transforms(CenterCrop(), RoundedCorners(16))
Glide
.with(context)
.load( url )
.apply(requestOptions)
.into( mBinding.element )
Glide
.with(context)
.load( url )
.apply(RequestOptions.circleCropTransform())
.into( mBinding.element )
Glide
.with(this)
.apply(RequestOptions.centerCropTransform())
.load( url )
.into( mBinding.element )
Glide
.with(this)
.asBitmap()
.apply(RequestOptions.centerCropTransform())
.load( url )
.into( mBinding.element )
Handler().postDelayed({
// Input Code
},delayMillis:Int = 1000)
fun isNetworkConnected(mActivity: Activity) : Boolean {
val connectivityManager ConnectivityManager = mActivity.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val activeNetwork = connectivityManager.activeNetworkInfo
return (activeNetwork != null && activeNetwork.isConnectedOrConnecting)
}
fun parseJson(str: String) : JsonObject? {
var result: JsonObject?
var jsonParser = JsonParser()
result = jSonObject = jsonParser.parse(str) as JsonObject
}
fun parseJson(str: String) : JsonArray? {
var result: JsonObject?
var jsonParser = JsonParser()
result = jSonObject = jsonParser.parse(str) as JsonArray
}
fun countThings(list: List): Int {
fun _countThings(list: List, acc: Int): Int {
// stuff
_countThings(list, acc + 1)
}
return countThings(list, 0)
}
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_up"
android:layout_width="@dimen/px_120"
android:layout_height="@dimen/px_120"
android:layout_above="@+id/rv_list"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_gravity="right|bottom"
android:layout_marginRight="@dimen/px_20"
android:layout_marginBottom="@dimen/px_200"
android:background="@android:color/transparent"
android:backgroundTint="@android:color/transparent"
android:clickable="true"
android:onClick="@{(v) -> activity.onClick(v)}"
android:scaleType="center"
app:background="@android:color/transparent"
app:borderWidth="0dp"
app:elevation="0dp"
app:fabSize="auto"
app:srcCompat="@drawable/fab_image"
/>