- No title android activity
- Как удалить строку заголовка в студии Android?
- Android: Changing the Title of an Activity – setTitle works – android:label does not?
- 7 thoughts on “Android: Changing the Title of an Activity – setTitle works – android:label does not?”
- Statically Typed
- Android: Dynamic and Custom Title Bars
- Theme and Style Attributes
- Dynamically Updating the Default Title Bar
- Animated Title Bars
- Dynamically Updating the non-Default Title Bar
- A Custom Title Bar
- What Really Happens to the Default TextView With a Custom Title Bar
- Conclusion
No title android activity
Полный текст статьи и исходники программы доступны только зарегистрированным участникам сайта.
Прочитайте внимательно условия! В начале каждой статьи указывается, к какому курсу относится данная статья. Например, если статья из 4 курса, значит нужно заплатить за все курсы по четвёртый включительно.
Стоимость регистрации — символические 350 рублей. После регистрации у вас будет доступ ко второму курсу.
Для регистрации сначала необходимо пополнить ЮMoney(бывший Яндекс.Кошелек) 410011383280263 на указанную сумму (или Webmoney-кошелек P894989790291 (старый R390884954122) или QIWI (перевод по никнейму), а затем прислать письмо на адрес alexander.klimoff@gmail.com с указанием, на какой кошелёк вы делали оплату и реквизиты, по которым можно вас определить (не прикрепляйте к письму картинки или файлы). Учитывайте комиссию при переводах.
Не присылайте в письме мои номера кошельков — поверьте, я их знаю и без вас.
В ответном письме вы получите учётные данные для чтения статей из закрытой зоны за второй курс.
Доступ к третьему курсу обучения доступен только после оплаты второго курса и составляет 350 руб.
Доступ к четвёртому курсу обучения доступен после оплаты третьего курса и составляет 350 руб. и т.д.
При оплате сразу всех курсов одновременно (2-9) цена составит 2800 руб.
Доступ даётся как минимум на один год. Для тех, кто оплатил третий и другие курсы, сроки доступа увеличиваются.
Также возможен приём на PayPal (только для зарубежных пользователей). Обратите внимание, что в этом случае стоимость одного курса составляет 7$.
Источник
Как удалить строку заголовка в студии Android?
В моем приложении эта строка заголовка находится вверху, там, где должно быть дополнительное меню, но мне не нужны настройки, и у меня только один экран. Когда я меняю тему, как описано во многих других вопросах, я получаю старую тему 2.2. Я хочу иметь современную тему только без панели наверху.
Перейдите в styles.xml и измените его .DarkActionBar на .NoActionBar
если цвета не имеют отношения к вашему приложению, вы можете выбрать
В файле манифеста Изменить:
работает onCreate() при setContentView() вызове перед .
иначе он выйдет из строя
В файле styles.xml измените DarkActionBar на NoActionBar
Это работает для меня
В файле манифеста измените на это:
Это работало для меня при values/styles.xml добавлении элементов:
Перейдите в Project -> app -> main -> res -> values -> styles.xml
Измените эту строку, если хотите удалить ее для каждого просмотра
если вы хотите сделать это только для одного представления, вы можете изменить его в своих данных манифеста. Заходим в Android -> манифесты -> AndroidManifest.xml. сделать следующее:
- Найдите представление, в котором вы хотите получить изменения этого типа
- Добавить android:theme=»»@style/Theme.AppCompat.NoActionBar»
вы можете изменить name = «———«
найти android: theme = «@ style / AppTheme» измененный на android: theme = «@ style / no_title»
нажмите выбрать тему в строке меню (зеленый цвет рядом с MainActivity)
- нажмите тема проекта
- щелкните no_title (справа от вас)
- нажмите ОК
Источник
Android: Changing the Title of an Activity – setTitle works – android:label does not?
To change the title of an activity (to show a more custom title for a certain activity than the application title), you can set the new title either through calling setTitle(«foo») on the activity or by setting android:label=»@string/price_after_rebate» in your activity style.
The problem was that the latter didn’t work, while the first one did. I try to keep any static definitions related to the activities outside of the code itself, but that’s hard when it doesn’t work as expected.
Turns out that if there’s a title set in the AndroidManifest.xml file (located under app/manifests/ in the standard layout / Android Studio), it’ll override any title set elsewhere in the definitions. You can change the specific titles by setting android:label=»@string/price_after_rebate» on the activity definitions in the manifest instead of the activity xml file:
7 thoughts on “Android: Changing the Title of an Activity – setTitle works – android:label does not?”
what to do if the latter does not work?
That probably means its time to post a question on Stack Overflow with a minimal example attached.
good but how can change activity level with java code
thanks
It’s literally the first paragraph in the post (I assume you meant label, not level):
To change the title of an activity (to show a more custom title for a certain activity than the application title), you can set the new title either through calling setTitle(“foo”) on the activity
one small doubt ,that is i need to display
Address :asd
Rollnumber:1
what is the code in android
This solution works if you re finding that you can set the title once, but can t change it after that. Make sure you re setting the title of the Collapsing Toolbar. Hylianpuffball Nov 27 ’18 at 16:13
Источник
Statically Typed
because Hindley-Milner rocks
Android: Dynamic and Custom Title Bars
Arguably the worst part in playing around with Android is its insistence to put that ugly title bar above everything I do as a default to my Activities. Really, Google, was that necessary? I think you could have done better and I know that I can do better. Thankfully you gave us free reign to substitute a custom variant or edit it out altogether. This post is going to explore the ways in which we can create custom title bars and more importantly just how far we can push the limits (of bad taste?)
This post is going to go into the internals of some of the Android classes and platform. We’ll focus our attention on things related to the Title Bar. If that isn’t of interest to you there are several Q&A/Blog posts that could very easily be of interest:
They’ll provide you with some ideas and inspiration but they won’t give you the “why” it works that way. Why almost always takes more time than most people are willing to spend. Hopefully, I can spend that time for you. Please feel free to correct me when I’m wrong (my ego isn’t large enough to not welcome criticism.)
Theme and Style Attributes
At the basic level Title bars are controlled by a combination of Style and Theme parameters. Styles influence Layouts and Themes, Activities. This distinction is important and good programming practice should promote separation of concerns; Android developers are no exception.
To understand how the Title Bar is laid out in an unmodified, plain, vanilla application look first at the standard Theme found in the Android kernel repository for Themes. The following three attributes containing the word “Title” stand out in the “Theme” Theme:
Following the references from the default Theme to the Android kernel repository for Styles, we first find the “WindowTitle” Style:
The attributes “singleLine,” “shadowColor,” and “shadowRadius” imply that the Title Bar is nothing more than a TextView. This is further backed up by the attributes in the “DialogWindowTitle” in the next Style group:
For completeness, the “WindowTitleBackground” Style:
contains a reference to a drawable.
As I said at a basic level this is what controls the default look and feel of the Title Bar within an Android App. Anything that can be done within the XML resources of a TextView can be done in the Style attributes to yield something different from default. You will have to write your own Theme which makes use of the new Style and tie it in the manifest file.
Dynamically Updating the Default Title Bar
The Android developers at Google realized people using their SDK might have the need to modify the text or the text color of the Title Bar. Activity provides four methods, two mutators and two accessors handling the text and text color local state. Changing either property of one Activity will not impact other Activities of the application. To prove the point look at the Activity code on the Android git repository:
Notice that the code delegates the process of setting the text and text color to the contained Window class using setTitle and setTitleColor. This will be important later.
Thus, if all you want to do is dynamically update the text of the Title Bar or the color of that text use those two methods. You can call them from anywhere in the Activity code and expect that the Title Bar will redraw itself.
Animated Title Bars
Getting back to the Styles and Themes, the background drawable seems like a perfect first step in adding something more profound to the Title Bar. In the last post to create a dynamic Splash Screen I made the background transparent and placed an animation overlay across the entire view extent (with ample padding.) A TextView is more limited as we are not dealing with a full Activity and probably should avoid placing anything transparent within its background for aesthetic reasons. I say probably because there are some of you who may wish to limit the size of the Activities without limiting the sizes of the Views. It’s a dirty hack. Let’s not indulge our wicked desires and look at animating the Title Bar.
Adding an animation to the Title Bar is almost as simple as replacing the background attribute drawable resource with an animation resource. The one catch is that we need to access the background of the TextView to set the animation in motion. In order to do that, we can’t exactly have things hidden away in the Theme and Styles section. We need it explicitly stated just as we would with any layout XML file and labled with an “id” attribute:
What follows next seems almost ludicrous, we have to ask our phone if it supports a custom title bar. I can only assume this is a carry over from earlier versions of Android as we’re perfectly safe to add in customized Title Bars through attributing Themes and Styles. And if it’s not, well, that’s why they pay you to develop Apps.
The code goes something like this:
After the feature request check we set the layout to our XML file and then go about adding in the layout for the Title Bar. We can not, however, attempt to call the “setContentView” method before requesting the new window feature. If you do your App will crash.
To get the animation started we call on our dear ol’ friend the AnimationUtils class:
I’ll leave out the XML for the animation resource. (One comment: This animation will run for the entire lifetime of the Activity and consume precious resources in doing so. Android is powerful but it is still quite limited. Animations aren’t easy on the CPU that ships with some phones.)
Dynamically Updating the non-Default Title Bar
Changing the Title Bar due to actions of the user is just as easy as dynamically adjusting any TextView as long as you can call upon it by id. The only thing you can’t do is hide it. That can only be done setting the FEATURE_NO_TITLE before the call to “setContentView” or within the Theme itself. If you want the option to hide it dynamically, place a TextView within the layout and forget about a Title Bar.
What about the four methods linked to the Activity that were mentioned above? Here’s the part that gets interesting: don’t use them! Go ahead and try to change the Title Bar text using the Activity methods. While you can change the state contained within the Activity itself your custom Title Bar stays static. But why?
Remember when I showed you that the call to Activity’s onTitleChanged delegates to Window‘s setTitle and setTitleColor methods? Let’s have a look at what those look like underneath the hood. Again, we go to the Android git repository:
and meet an abstract base class. No problem, right? Consulting the documentation on the Android resource pages yields the catch-phrase: “The only existing implementation of this abstract class is android.policy.PhoneWindow.” And following that down to the Google Groups Android page gives us this conversation wherein we find out:
As you say, this is an internal class, so not appropriate to discuss on
android-developers (which is for the SDK)…
-Dianne Hackborn, Android framework engineer
This implies it’s not within the general repository where we’re accustomed to finding the implementation details. Nor is it mentioned on the Android developer pages. We’ll need to look at the highest level of the framework repository, within the “internal” section (Don your Dick Tracy hats.)
PhoneWindow is found in the framework base, policy section of the code. It took a little sleuthing to find (why can’t they make it easy?) but eventually we can see the implementation details of setTitle and setTitleColor:
And mTitleView is a TextView that appears to not have been set. That’s why you can’t even attempt to trick the Activity by calling the getWindow method to set the title and title color directly. If you do, nothing will happen to the UI but you’ll be able to see that the state of the Window is modified from the code.
A Custom Title Bar
You are not restricted to only a TextView for the Title Bar. In fact, there’s even a way to place an icon on your Title Bar built into the Android Activity code. I won’t get into that here because that’s what I would consider part of the “plain, old, vanilla” Title Bar.
Just like what was done up above in adding an animated background to the Title Bar, making a unique Title Bar involves creating a layout XML resource file. I suggest wrapping your custom Title Bar within a LinearLayout horizontally positioned but you’re free to do whatever you wish:
You don’t need to do anything further but if you’re going to go this far why not shoot for the moon? I’ll modify the Theme so that it’s large enough to fit a Button and I’ll even link to new background Styles just to make this really custom:
Within the Title Bar Styles, let’s remove the single line feature of the Title Bar (you never know,) change the shadowing so it stands out from what will be the actual background, and provide the reference to the drawable resource that’ll be the background:
With all that in place it’s time to see what it looks like:
Yup, that’s pretty awful. This would never go out to a client. I think you can tell why.
What Really Happens to the Default TextView With a Custom Title Bar
Above I mentioned that it appears that the TextView of the PhoneWindow is never set. I lied. It’s not that simple but the explanation would have detracted from the flow of this article. This is where it belongs for those that are truly curious to the inner workings of Android.
There is no place where I could find where the TextView is set to null either in the PhoneWindow or Window source code. However, I did find that the TextView is set to GONE if the mLocalFeatures variable is set to just the right value. GONE means that the TextView is not only invisible but also occupies no space within the layout. Technically speaking, setting the text and text color of the Title Bar really did change the state of the TextView. You just couldn’t see it.
Here is the code in PhoneWindow responsible for setting the state of the internal TextView:
The getLocalFeatures function returns the mLocalFeatures variable. Down in the source code for Window the mLocalFeatures variable is set:
This is why you need to request the window feature before it setting the Content of the Activity. The PhoneWindow needs to check the variables in the proper order to flag the TextView GONE.
Conclusion
Android provides you wish ample means to modify not only the UI of the Title Bar but also it’s behavior. You are limited only by your imagination but it’s important to understand that some convenience methods are lost when working with customized applications. Underneath the hood there are several assumptions made about an application, the UI state, and appearance that if not flagged in the right order will cause your App to crash before it has a chance to load.
If you have any more questions or want an explanation of some other facet working with Title Bars let me know. My blog posts have slowed down recently but they’re also much, much longer than they used to be and take an inordinate amount of time to write between side projects and life. That said, if asked I will attempt to answer, it just might take a bit.
Источник