androidtitle
『壹』 android 極光通知欄的title怎麼接的
參考官方AndroidSDK教程完成激光推送的基本配置區別通知和自定義消息通知即指在手機的通知欄(狀態欄)上會顯示的一條通知信息。自定義消息是極光推送自己的概念。自定義消息不是通知,所以不會被SDK展示到通知欄上。其內容完全由開發者自己定義。自定義消息主要用於應用的內部業務邏輯。一條自定義消息推送過來,有可能沒有任何界面顯示。本篇博客介紹的就是使用自定義通知實現上圖效果。實現自己定義的Receiver,並參考官方文檔在AndroidManifest.xml中配置。packagecom.cn.cwvs.fruit;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.HashMap;importjava.util.Map;importorg.json.JSONException;importorg.json.JSONObject;importandroid.content.BroadcastReceiver;importandroid.content.Context;importandroid.content.Intent;importandroid.os.Bundle;importandroid.util.Log;importcn.jpush.android.api.JPushInterface;{privatestaticStringTAG="pushreceiver";@OverridepublicvoidonReceive(Contextcontext,Intentintent){Bundlebundle=intent.getExtras();Log.d(TAG,"onReceive-"+intent.getAction());if(JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())){}elseif(JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())){//自定義消息不會展示在通知欄,完全要開發者寫代碼去處理Stringcontent=bundle.getString(JPushInterface.EXTRA_MESSAGE);Stringextra=bundle.getString(JPushInterface.EXTRA_EXTRA);System.out.println("收到了自定義消息@@消息內容是:"+content);System.out.println("收到了自定義消息@@消息extra是:"+extra);//**************解析推送過來的json數據並存放到集合中begin******************Mapmap=newHashMap();JSONObjectjsonObject;try{jsonObject=newJSONObject(extra);Stringtype=jsonObject.getString("type");map.put("type",type);}catch(JSONExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}map.put("content",content);//獲取接收到推送時的系統時間CalendarrightNow=Calendar.getInstance();SimpleDateFormatfmt=newSimpleDateFormat("yyyy-MM-dd");Stringdate=fmt.format(rightNow.getTime());map.put("date",date);MyApp.data.add(map);//**************解析推送過來的json數據並存放到集合中end******************}elseif(JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())){System.out.println("收到了通知");//在這里可以做些統計,或者做些其他工作}elseif(JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())){System.out.println("用戶點擊打開了通知");//在這里可以自己寫代碼去定義用戶點擊後的行為Intenti=newIntent(context,MainActivity.class);//自定義打開的界面i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(i);}else{Log.d(TAG,"Unhandledintent-"+intent.getAction());}}}
『貳』 Android怎麼取消標題欄默認內容
Android開發去除標題欄title其實非常簡單,他有兩種方法,一種是在代碼中添加,另一種是在AndroidManifest.xml中添加:
1、在代碼中實現:
在此方法setContentView(R.layout.main)之前加入:
requestWindowFeature(Window.FEATURE_NO_TITLE);標題欄就沒有了。
2、在AndroidManifest.xml中實現:
注冊Activity時加上如下的一句配置就可以實現。
<activity android:name=".Activity"
android:theme="@android:style/Theme.NoTitleBar">
</activity>
『叄』 怎麼自定義Android標題欄修改TitleBar的布局
Android程序默認的Activity標題欄只能顯示一段文字,而且不能改變它的布局、顏色、標題欄的高度等。如果想要在標題欄加上個圖標、button、輸入框、進度條、修改標題欄顏色等,只能使用自定義的標題欄。自定義標題欄可以通過在onCreate函數中添加以下代碼來實現,需要注意的是代碼的順序必須按照下面的樣式,否則將無效。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.mainactivity); //Activity的布局
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.titlebar); //標題欄的布局
雖然上面這樣可以在標題欄加入一些控制項,但是仍然不能改變標題欄的高度、背景色,要想達到這個目的,只能使用theme(主題)。因此往project里先添加一個style。改變背景色修改android:windowTitleBackgroundStyle的值,改變標題欄高度則修改android:windowTitleSize的值。下面是一個示例:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#778899</item>
</style>
<style name="activityTitlebar" parent="android:Theme">
<item name="android:windowTitleSize">32dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
接著再修改AndroidManifest.xml文件,找到要自定義標題欄的Activity,添加上android:theme值,比如:
Java代碼
<activity android:name=".MainActivity" android:theme="@style/activityTitlebar">
<activity android:name=".MainActivity" android:theme="@style/activityTitlebar">
android:theme值就是上面那個style.xml文件里定義的一個style的name值。
按照以上的步驟,修改標題欄布局、高度、背景色的功能就實現了。
『肆』 android title上的圖標怎麼去掉
有時候在一些子頁面或者內容頁面,不需要顯示ActionBar的標題欄圖標。可用如下方式進行設置。
首先獲取到ActionBar對象
ActionBar actionBar=getActionBar();
使用android:logo屬性。不像方方正正的icon,logo的圖像不會有任何寬度限制。
logo圖像典型的給你的APP提供品牌。當有Logo的時候,可以隱藏label。
默認的,ActionBar使用Activity的android:icon屬性,還有一致的android:label屬性。
隱藏Label標簽:actionBar.setDisplayShowTitleEnabled(false);
隱藏logo和icon:actionBar.setDisplayShowHomeEnabled(false);
設置標題,一個主標題,一個子標題
actionBar.setSubtitle(「Inbox」);
actionBar.setTitle(「Label:important」);
默認的ActionBar的背景顏色取決於activity指定的Theme。Holo Theme它的背景是黑色的。
可以指定任意的Drawabel對象作為背景,使用setBackgroundDrawable方法:
ActionBar actionBar = getActionBar();
Resources r = getResources();
Drawable myDrawable = r.getDrawable(R.drawable.gradient_header);
actionBar.setBackgroundDrawable(myDrawable);
注意:ActionBar會自動縮放你的背景圖
覆蓋模式
默認情況下,actionBar放在activity的頂部,且作為activity布局的一部分。設置成為覆蓋模式後,actionBar相當於漂浮在activity之上,不幹預activity的布局。設置如下:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
setContentView(R.layout.main);
}
『伍』 如何修改android標題欄界面
方法一、在你的那張Activity中onCreate方法中加上下面代碼:
?
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main); //軟體activity的布局
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); //titlebar為自己標題欄的布局
但是新的問題又來了,這樣是無法深層的定製標題欄的,比如原有的高度和背景都沒有發生變化,那有沒有好的方法呢?答案是有的、
方法二:
因此先定義一個style,若修改背景請修改android:windowTitleBackgroundStyle
若修改標題欄高度,請修改android:windowTitleSize
例子:
?
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="schemas.android.com/apk/res/android">
<style name="CustomWindowTitleBackground">
<item name="android:background">#565656</item>
</style>
<style name="test" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>
在程序的android_manifest.xml中對應activity中添加屬性android:theme = "@style/test" 就可以了
?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="schemas.android.com/apk/res/android"
package="com.guardian"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name" >
<activity android:name=".Test"
android:label="@string/app_name"
android:theme = "@style/test" //就在這里
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
『陸』 Android開發如何去除標題欄title
android中取出標題欄,主要是通過設置windows的模式,可以通過在主配置文件或者代碼中進行設置:
1.使用Window.FEATURE_NO_TITLE設置沒有標題,當然也有很多其他屬性:
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題欄,一定要在setContentView之前
setContentView(R.layout.history);
}
2.在android工程中的主配置文件manifest.xml中配置
<applicationandroid:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"><!--NoTitleBar就是沒有標題欄-->
除了沒有標題欄以外,開發者還可以自定義標題欄,如下很多屬性的解釋:
1.DEFAULT_FEATURES:系統默認狀態,一般不需要指定
2.FEATURE_CONTEXT_MENU:啟用ContextMenu,默認該項已啟用,一般無需指定
3.FEATURE_CUSTOM_TITLE:自定義標題。當需要自定義標題時必須指定。如:標題是一個按鈕時
4.FEATURE_INDETERMINATE_PROGRESS:不確定的進度
5.FEATURE_LEFT_ICON:標題欄左側的圖標
6.FEATURE_NO_TITLE:吳標題
7.FEATURE_OPTIONS_PANEL:啟用「選項面板」功能,默認已啟用。
8.FEATURE_PROGRESS:進度指示器功能
9.FEATURE_RIGHT_ICON:標題欄右側的圖標
『柒』 android 默認title 怎麼設置
Android開發去除標題欄title其實非常簡單,他有兩種方法,一種是在代碼中添加,另一種是在AndroidManifest.xml中添加:
1、在代碼中實現:
在此方法setContentView(R.layout.main)之前加入:
requestWindowFeature(Window.FEATURE_NO_TITLE);標題欄就沒有了。
2、在AndroidManifest.xml中實現:
注冊Activity時加上如下的一句配置就可以實現。
<activity android:name=".Activity"
android:theme="@android:style/Theme.NoTitleBar">
</activity>
『捌』 android 怎樣設置title 居中顯示
1在onCreate()方法中加上這三句話:
[java] view plain
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title);
在布局文件中新建一個title.xml文件:
[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http //schemas android com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView android:id="@+id/textTile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title" />
</LinearLayout>
『玖』 android 怎麼讓toolbar上面的title居中
自帶的settitle是居左的,可以自定義一個textview,如下方式:
Android自帶的toolbar有設置title的功能,但是設置的title都是居左的,但是很多需求都是要title居中,主要的方法就是:不使用setTitle,而是在toolBar的xml定義中插入一個TextView,然後設置其layout_gravity為center,它就在正中間了。。
1、定義toolbar的xml文件
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="@color/primary">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:singleLine="true"
android:textColor="@color/white"
android:textSize="20sp" />
</android.support.v7.widget.Toolbar>
具體代碼中使用toolbar
public Toolbar initToolbar(int id, int titleId, int titleString) {
Toolbar toolbar = (Toolbar) findViewById(id);
// toolbar.setTitle("");
TextView textView = (TextView) findViewById(titleId);
textView.setText(titleString);
setSupportActionBar(toolbar);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null){
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
}
return toolbar;
}