android.view View getContext() method returns the context the view is running in, through which it can access the current theme, resources, etc.
Example 1:
TextView textView = findViewById(R.id.text_view); Context context = textView.getContext(); Resources resources = context.getResources(); int color = resources.getColor(R.color.red);
In this example, the getContext method is used to obtain the context of a TextView widget. The context is used to obtain the resources associated with the view, in this case the color resources, which can be used to set the text color of the TextView widget.
In this example, the getContext method is used to get the context associated with an ImageButton widget. The context is used to create an intent object which is used to launch a new activity called SecondActivity.
Package library: android.view
Java View.getContext - 30 examples found. These are the top rated real world Java examples of android.view.View.getContext extracted from open source projects. You can rate examples to help us improve the quality of examples.