2014-10-29 20 views
9

Xin chào, tôi đã tạo một hoạt động mở rộng ActionBarActivity & sử dụng chủ đề material trong ứng dụng của tôi. Trong thanh hành động, nút quay lại không hiển thị.Nút Quay lại thanh tác vụ không hiển thị trong Android

Tôi không tìm thấy lý do tại sao nó không hiển thị. Bất kỳ giúp đỡ?

public class RegistrationActivity extends ActionBarActivity { 

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

     getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_background_light)); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 
     getSupportActionBar().setHomeButtonEnabled(true); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light"> 
    <!--Support Library compatibility--> 
    <item name="actionBarStyle">@style/MyTheme.ActionBarStyle</item> 
</style> 

<!-- ActionBar styles --> 
<style name="MyTheme.ActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar"> 
    <!--Support Library compatibility--> 
    <item name="titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item> 
</style> 

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"> 
    <item name="android:textColor">@android:color/white</item> 
</style> 

AndroidManifest.xml

<activity 
     android:name=".RegistrationActivity" 
     android:label="@string/title_activity_registration" > 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value=".HomeScreenActivity" /> 
    </activity> 

Cảm ơn trước.

+1

Sử dụng 'Theme.AppCompat.Light.DarkActionBar' nếu bạn muốn biểu tượng/văn bản xuất hiện màu trắng trong thanh tác vụ. – ianhanniballake

+0

@ianhanniballake yes đã cảm ơn :) –

Trả lời

26

thêm tài sản

getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

để hiển thị nút "trở lại"

+0

Điều này đã được thực hiện, như có thể được nhìn thấy từ câu hỏi. –

2

Nếu giải pháp của Jorgesys không làm việc cho bạn. Thử ghi đè phương thức onOptionsItemSelected.

public class MyActivity extends AppCompatActivity 
{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.my_activity); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) 
    { 
     int id = item.getItemId(); 
     if (id == android.R.id.home) 
     { 
      onBackPressed(); 
      return true; 
     } 
     else 
     { 
      return super.onOptionsItemSelected(item); 
     } 
    } 
} 
Các vấn đề liên quan