2017-06-12 29 views
2

アプリ名にアプリ名が表示されていません。その白い。どうしてか分かりません。助けてください。それは前に示していた。その後、私は今、変化の多くを作ってアンドロイドマニフェストアンドロイドのツールバーにアプリ名が表示されないのはなぜですか?

主な活動で

.... 
<android.support.v7.widget.Toolbar 
    android:id="@+id/my_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary" 
    android:elevation="4dp" 
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar" 
    android:visibility="visible" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 


    .... 

</RelativeLayout> 
スタイルで

<!-- Base application theme. --> 
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
</style> 

を修正することができません

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:supportsRtl="true" 
    android:theme="@style/Theme.AppCompat.Light.NoActionBar" 
    > 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

public class MainActivity extends AppCompatActivity { 

    public static final String LOG_TAG = MainActivity.class.getName(); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); 
     setSupportActionBar(myToolbar); 

     // Set the content of the activity to use the activity_main.xml layout file 
     setContentView(R.layout.activity_main); 

     // Find the view pager that will allow the user to swipe between fragments 
     ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); 

     // Create an adapter that knows which fragment should be shown on each page 
     ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); 

     // Set the adapter onto the view pager 
     viewPager.setAdapter(adapter); 

     TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); 

     // Connect the tab layout with the view pager. This will 
     // 1. Update the tab layout when the view pager is swiped 
     // 2. Update the view pager when a tab is selected 
     // 3. Set the tab layout's tab names with the view pager's adapter's titles 
     //  by calling onPageTitle() 
     tabLayout.setupWithViewPager(viewPager); 

    } 
} 
+0

res> values> stringsにアプリケーション名を指定していますか? –

+2

'myToolbar'初期化と' setSupportActionBar() '呼び出しを' setContentView() 'の後に移動する必要があります。 –

答えて

2

どちらかあなたのjavaファイルでこれを追加します。それは、それが見えるようにするshow title barプロパティのためにtrueを設定します。

getSupportActionBar().setDisplayShowTitleEnabled(true); 

それとも

app:title="@string/app_name" 

appツールバー要素の下に、あなたのxmlでこれを追加サポートライブラリウィジェットに含ま性質を示すために使用されます。

最も重要なのはstring.xmlファイルにapp_name文字列があることです。タイトルの

センター

にあなたは、アクションバーのために、独自のカスタムレイアウトを設計し、それにそれを設定する必要があります。 How to set title in centre in ActionBar?

+0

ありがとうございます。テキストを中央に揃える方法を知っていますか? – ams92

+0

回答が編集されました。見てみましょう。 –

0

あなたは次のように行うことができます。..

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); 
setSupportActionBar(myToolbar); 
myToolbar.setTitle("Your App Name"); 
0

スタイル

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> </style> 

ではここで問題です。 NoActionBarを置くと、上部にバーが表示されません。

DarkActionBarには、変更を行う前のデフォルトのActionBarを設定する必要があります。

希望すると助かります!

+0

アプリがクラッシュする - https://developer.android.com/training/appbar/setting-up.htmlに従って、追加する必要があります。これらのテーマのいずれかを使用すると、アプリがネイティブのActionBarクラスを使用してアプリバーを提供することができなくなります。 – ams92

関連する問題