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

Eclipse can't find logback-test.xml on my classpath for unit tests
Creating Methods in Separate Classes
Abstract Class with enum Comparator: How to make it work?
binary search on array of integer in java
Using Nested for loops to make a doubling then halfing pyramid
Reading binary data in Java
Java subclass constructor inherited member
embedded im-memory database in maven
correct the Book class to get output of getBooksByAuthor method
Gradual increase in Resident Memory usage by Jboss(Java) process
JNI - make an instance of another C++ class
is there a way to know java packages in a jar file? [duplicate]
Difference between call and execution in AOP
Retrieve selected strings from a list of words using Java
GXT 3.x : Dynamic freeze/lock columns. Autosize the grids
NumberFormatException when connecting LDAP server with IPv6

Categories

HOME
xamarin
multithreading
testng
netbeans
push-notification
android-4.4-kitkat
jsrender
survey
callback
cross-browser
ebean
directx
upload
virtualization
quicklook
handsontable
modx-revolution
apache-cayenne
spring-tool-suite
ups
decimal
netflix
after-effects
pc
invantive-sql
alpine
icloud-api
sparse-matrix
kannel
user-interaction
buck
c++-amp
skia
bluestacks
jspresso
stringtemplate
mpmediaquery
bytecode-manipulation
libraries
bootstrapper
elmah
google-closure
nand2tetris
eigenvalue
estimote
s
executenonquery
scrollable
paxos
python-webbrowser
blogengine.net
svmlight
setter
knockout-components
directory-structure
windows-mobile-6.5
dwscript
pycaffe
visual-c++-2008
wdf
httplistener
infix-notation
azure-virtual-network
pcf
etsy
gstreamer-0.10
pagedlist
hover-over
execute
eclipse-clp
atk4
citrus-pay
twirl
php-ci
ami
geonetwork
phalanger
applescript-objc
java-metro-framework
preferences
document-classification
contenttype
expected-exception
comexception
android-2.2-froyo
transcoding
aqtime
gridfs
sitemesh
apc
quartz-graphics
tws
gridcontrol
dataadapter
android-screen-support
browser-detection
mt
quickdialog
funscript
pysimplesoap
appconkit
buildr
gnu-prolog
libc++
ecl
remember-me
createwindow
sproutcore-2
xsdobjectgen
castle-monorail
ncqrs
firefox-5
zend-tool
adrotator
anti-piracy
noscript
sector

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