2017-07-15 15 views
0

私は崩壊しているツールバーを持っています。それが崩壊すると、私はアプリのバーのタイトルを設定しますが、そのアプリのバーのタイトルを削除することはできません。展開条件(verticalOffset == 0)が実行されていますが、タイトルが変更されていないようです。なぜアプリケーションバーのタイトルが変更されないのですか?

public class MovieDetailsActivity extends AppCompatActivity implements AppBarLayout.OnOffsetChangedListener{ 

    private CollapsingToolbarLayout collapsingToolbarLayout; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_movie_details); 

     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 

     ... 

     collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout); 

     AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.app_bar); 
     appBarLayout.addOnOffsetChangedListener(this); 

     ... 
     setTitle(""); 
     ... 

    } 

    @Override 
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { 
     if (Math.abs(verticalOffset) == appBarLayout.getTotalScrollRange()) { 
      //Closed 
      setTitle("Tmovies"); 
      Log.i("test","Closed"); 

     } else if (verticalOffset == 0) { 
      // Expanded 
      setTitle(""); 
      Log.i("test","Expanded"); 
     } else { 
      // Somewhere in between 

     } 
    } 
} 

答えて

0

使用toolbar.setTitle(...)代わりsetTitle(...)

0

のあなたはsetSupportActionBar後に動作しない可能性があります後者としてgetSupportActionBar().setTitle("My Title");代わりのtool.setTitle("My Title");好む必要があります。

+0

残念ながらまだ動作していません – ams92

関連する問題