Android - change custom title view at run time -


I'm using a custom title view in my app for each activity, one of the activities based on button clicks In, I need to change the custom title view. Now when I call to set a feature, it works fine every time.

But if I try to update any item in the custom title (change the text of the title or see a lesson on the title), it does not get updated.

Debugging through the code shows that text view and button examples are not empty and I can also see the custom title bar. But text has not been updated on text view or button. Has anyone else had to face this problem? How do I solve it?

Thank you.

Edit

Any attempt I made here is not updated even when I call Post in Evaluate.

  getWindow () SetFeatureInt (window.FATURE_CUSTOM_TITLE, R.layout.text_title); TextView Database = (TextView) Find VVBIID (RaidTitle_text); Databar.setText ("some text"); Databar.postInvalidate (); Button left button = (button) Find ViewById (R.id.left_btn); LeftButton.setOnClickListener (mLeftListener); LeftButton.setText ("Left BTN"); LeftButton.postInvalidate (); Button rightBtn = (button) findViewById (R.id.right_btn); RightBtn.setOnClickListener (mRightListener); RightBtn.postInvalidate ();  

The problem is that only the implementation () uses it in setFeatureInt Installs with the method and the new layout and attachToRoot = true . As a result, when you call setFeatureInt , the new layout is not replaced but attached is not in the internal title container and thus the one-

You can solve it by using the following supporting method instead of setFeatureInt . Before setting up a new custom title feature, the Auxiliary removes all views from the internal heading container directly:

  Private zeros set custom_style (int value) {try com // com.android.internal .R .id.title_container (= 0x1020149) Int titled container id = (integer) class. ForName ("com.android.internal.R $ id"). GetField ("title_container") Get (null); // Delete all views titled Container ((View group)) () FindViewById (titleContainerId). RemoveAllViews (); // View new custom title (add) getWindow SetFeatureInt (Window.FEATURE_CUSTOM_TITLE, value); } Hold (exception before) {// what you want to do here ..}}  

I'm not sure the current setFeatureInt behavior is intended, but This is certainly not one way or another document, so I will take it to Android Devs;)

Edit

As explained In the comments, the preceding solution is not optional. Instead of relying on com.android.internal.R.id.title_container , you can hide the old custom title whenever you set a new one.

Assume that you have two custom title layouts:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RelativeLayout Android: id = "@ + id / custom_title_1" ...  

and

  & lt ;? Xml version = "1.0" encoding = "utf-8" & gt; & Lt; RelativeLayout Android: id = "@ + id / custom_title_2" ...  

and you want to replace custom_title_1 with custom_title_2 . , You can hide the pre and use setFeatureInt to add later:

  findViewById (R.id.custom_title_1) .setVisibility (see. GONE); GetWindow () SetFeatureInt (window.fEATURE_CUSTOM_TITLE, R.layout.custom_title_2);  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -