java


Android Toolbar Subtitlte to a String


I have a toolbar, but how can I set the subtitle to a string resource?
I want that the subtitle is a string. How can I do this?
My MainActivity.java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setSubtitle(#string/test1);
}
}
My content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main" tools:context=".MainActivity">
<TextView android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
My activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
My styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay"
parent="ThemeOverlay.AppCompat.Light"
/>
</resources>
My strings.xml:
<string name="app_name">Test</string>
<string name="action_settings">Settings</string>
<string name="test1">Test1</string>
<string name="test2">Test2</string>
Since setSupportActionBar(toolbar); you should be able to use
getSupportActionBar().setSubtitle(getString(R.string.test1));
toolbar.setSubtitle(getString(R.string.test1)); should do it as well
You can use toolbar.setSubtitle(R.string.test1);

Related Links

Calling SetRefreshing(false) outside main thread is not allowed. Workaround?
Convert int to Calendar Object
Hibernate 5.2.10 with Spring 4.3.8 Error in org.hibernate.SessionFactory.openSession()
Database application error
Scanning multiple Strings to ArrayList returns unexpected result. (Java, simple, beginner)
Spring State Machine Transitions
do you have to make class static if no non-static class members? [duplicate]
Java: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
Is arithmetic allowed in a Java array subscript? [on hold]
How to sort list of objects with a property of another object in Java?
Retrofit2 Sending Array as HashMap results in a different format
Output parsed Json data
Trying to get KeyBindings to work
Java STS: UCanAccess connection error “cannot load driver class”
Spring+JPA+REST configuration
Is there a way to send an Offline Conversion event to Facebook using restfb?

Categories

HOME
ms-access
pypi
fft
syntax
sharepoint-designer
binary-tree
win32gui
swagger-ui
portia
kibana-4
spring-tool-suite
designer
normalizr
lucene.net
scichart
nas
conemu
visjs
facebook-instant-articles
devops
one-to-many
windowbuilder
gsmcomm
sql-server-2012-express
socialengine
nameservers
galsim
exuberant-ctags
oracle-fusion-middleware
vsts-build-task
mozilla
language-concepts
overlap
jquery-bootgrid
scaffold
particles.js
preconditions
eclipse-scout
grid.mvc
angular2-meteor
logfiles
dropbox-php
svmlight
lowpass-filter
imanage
titanium-android
account-kit
transmitfile
ctest
impresspages
holder.js
simplewebrtc
suffix-tree
asp.net5
cloudbees
simple-framework
feedback
wireshark-dissector
sysinternals
skos
csquery
system.reflection
facebook-graph-api-v2.4
ng-animate
knuth
markers
sgen
contenttype
hippomocks
marmalade
uv-mapping
dbconnection
eclipse-memory-analyzer
kyotocabinet
bluepill
viewswitcher
onsubmit
nsobject
vdsp
mod-auth
f#-powerpack
horizontal-accordion
rfc1123
servicehost
celltable
filtered-index
perfect-hash
thunderbird-lightning
database-management
ugc

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App