I am learning Android and wondering why I cannot find the real attribute target tools:contextin the XML layout file.
I read here https://developer.android.com/studio/write/tool-attributes.html#toolscontext under the image that onClickwon't work for any view until we specify tools:context.
I have tried and am wondering if it works without any. tools:context
I also read from stackoverflow that it used to select a suitable theme for the layout. But it works great for me without using tools:context, then what is the true purpose of this?
XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="CallIt"
/>
</RelativeLayout>
Primary activity:
package com.something.testingwith42;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void CallIt(View view){
Toast.makeText(this, "Checking", Toast.LENGTH_LONG).show();
}
}
Everything is working fine tools:context
user6685522