android - Why am I not able to change the title of my action bar? -
i tried change title of action bar using tips given in other answers don't seem work.i trying change title "test".
here activity_detectlayout.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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" tools:context="com.kaushik.abhishek.facedetecto.detectlayout"> <imageview android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/image_view" android:layout_weight="1.0" android:layout_alignparenttop="true" android:layout_alignparentright="true" android:layout_alignparentend="true" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/detect_face" android:text="@string/detect_face" android:layout_gravity="center_horizontal" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:background="#d4424646" android:textcolor="#fdfffa" />
detectlayout.java
package com.kaushik.abhishek.facedetecto; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; public class detectlayout extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getactionbar().settitle("test"); setcontentview(r.layout.activity_detectlayout); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_detectlayout, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
the manifest file
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minsdkversion="8" android:targetsdkversion="15" /> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="android.permission.camera"/> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".detectlayout" android:label="@string/title_activity_detectlayout" > </activity> </application>
styles.xml
<resources> <!-- base application theme. --> <style name="apptheme" parent="theme.appcompat.light.darkactionbar"> <!-- customize theme here. --> </style>
use on activity inside oncreate method.
getsupportactionbar().setdisplayhomeasupenabled(true); getsupportactionbar().settitle("your title");
or, change menifest
<activity android:name=".youractivity" android:label="your title" />
Comments
Post a Comment