-1
私は、アクションバーのタイトルを任意のテキストにプログラマチックに変更したいと考えています。appcompat v7ライブラリのアクションバータイトルの変更方法
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View actionBarview = inflater.inflate(R.layout.action_bar, null);
ActionBar actioBar = getSupportActionBar();
actioBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actioBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actioBar.setCustomView(actionBarview, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
final DrawerLayout drowerlayout = (DrawerLayout) findViewById(R.id.drawerlayout);
私が試した:私はここにAPPCOMPAT V7 を使用 は私のコードですactioBar.setTitle( "のMyText");
何も起こりませんでした。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_gravity="right"
android:background="#bfbfbf"
android:gravity="right"
android:orientation="horizontal" >
<TextView
android:id="@+id/TextView01"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="0.1"/>
<TextView
android:id="@+id/txtBName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="......"
android:textColor="#000" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="0.1"/>
<Button
android:id="@+id/btnMenu"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="menu" />
:
は、ここに私のカスタムアクションバーのxmlです。
ありがとう、私は質問を更新し、XMLコードを追加しました。私はtxtBNameにテキストビューのIDを設定するこれはあなたの意味ですか? – Alfi
それは完璧に機能しました!ありがとうございました! – Alfi
いつでも仲間にして、actionBarのカスタムビューを使用しながらGoogle標準に準拠するようにしてください。また、actionBarの代わりにactionBarの代わりにToolbarsを使用する方法を採用してください –