Mysterious_android
Mysterious_android

Reputation: 618

Adding view programmatically to a FragmentActivity dynamically

I want to add a Image icon to be added on top of rootView in FragmentActivity.

I tried doing this:

 ViewGroup rootLayout = (ViewGroup) activity.findViewById(android.R.id.content);
            myView = activity.getLayoutInflater().inflate(R.layout.iconimage, null);
            rootLayout.addView(myView );
            rootLayout.invalidate();

But realised that this only works for AppCompatActivity, and doesn't work for FragmentActivity. As my image cannot be seen.

How can i add Views to Classes that extends FragmentActivity?

Upvotes: 1

Views: 177

Answers (1)

Nabin Bhandari
Nabin Bhandari

Reputation: 16399

AppCompatActivity is a subclass of FragmentActivity so all features of FragmentActivity will be available in AppCompatActivity.

So making your activity extend AppCompatActivity should hopefully solve your problem.

Upvotes: 2

Related Questions