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

Are there any JBoss 5.1 Community Edition SecurityManager .policy file examples available?
Issues with the maximum number of CODs for an app
Intercepting Java field and method access, creating proxy objects
JPA: Table Relationship Issue
Java socket output has delayed first message
Rounding Error Approximations [duplicate]
preserving component state across multiple request cycles
How to run java class file inside the war file [duplicate]
Subselect to retrieve righthand-side of in-statement using CriteriaBuilder (JPA)
How can I find the android log file?
Should I instantiate a new Facebook variable for each activity, or use static Facebook variable
How do I return a (custom) SOAPFault from an Axis web service?
Is lazy=“false” the only solution for “org.hibernate.LazyInitializationException: could not initialize proxy – no Session”
How to solve “This element has no attached source and the Javadoc could not be found in the attached Javadoc”?
Problem, nothing is displayed while trying to read xml
high level java GUI framework [closed]

Categories

HOME
arduino-uno
wso2
openstack
minimum-spanning-tree
mockito
path-finding
google-api-php-client
appx
lodash
sd-card
survey
webpack-2
disassembler
fancybox
android-youtube-api
adfs
applepay
iggrid
metatrader4
tomcat6
offline
fortumo
flask-wtforms
django-admin
highlight.js
saxon
jqwidget
beyondcompare
custom-wordpress-pages
nas
swiftlint
android-widget
xpages-ssjs
buildbot
saas
libssl
socialengine
frame
phonegap
.net-4.0
airconsole
column-family
wpf-controls
host
io-redirection
space-complexity
espeak
webdriver-manager
streamreader
grid.mvc
ibpy
firebase-admin
reactive-cocoa-5
businessworks
thin
menuitem
taffy
termination
komodoedit
worksheet
sage-one
lift-json
knpmenubundle
mako
bind9
google-cdn
watchconnectivity
time-and-attendance
ableton-live
bonobo
nsfilemanager
mongocsharpdriver
pagedlist
skype4py
packagist
bluegiga
pyke
tcpserver
vhd
spim
sdhc
collapse
feedback
varargs
emailrelay
map-projections
ios9.1
vstest.console.exe
iiviewdeckcontroller
notify
apache-commons-net
bigbluebutton
rake-task
jscript.net
network-interface
cctv
id3v2
gulp-less
uitouch
navigationservice
htmlcleaner
uv-mapping
gnu-smalltalk
blending
back-stack
rabl
sabredav
enterprisedb
anonymous-methods
hosts-file
bigcouch
mercurial-server
doh
deobfuscation
calling-convention
pyinotify
preference
user-friendly
exchange-server-2003
sustainable-pace
private-members
ugc

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App