带按钮和标题的顶部导航栏
我正在制作一个android版本的应用程序,基于iOS之一,但是,我在制作顶部导航栏时遇到了麻烦。我实际上想创建一个类似于iOS界面的操作栏,但是,我不能添加close button,go back button和next button。带按钮和标题的顶部导航栏
首先,如果是家庭活动,顶部导航栏将包含居中标题和用于关闭当前活动的close button。如下图所示:
然后,如果用户已经有了一个正确答案(或在某些条件下),然后next button会显示出来,如果没有,也不会显示出来。
就像上面的图片,在图片1,用户可以回到Q1,为Q1已经是正确的。此外,Q2也是正确的,因为它可以进入Q3。然后,在图2中,Q3尚未回答,但不能进入Q4,但可以进入Q2。而且,如果去Q2,图片1的相同界面将显示(仍然包含了下,和后退按钮。
我现在有一个操作栏,但不能做任何事情,但只有一个标题。
的Manifest.xml:
<activity     android:name=".Problems" 
    android:configChanges= 
    "keyboard|keyboardHidden|orientation|screenLayout|uiMode| 
     screenSize|smallestScreenSize" 
    android:theme="@style/AccountSetting" 
    android:label="Problems" /> 
toolbarlayout.xml:
<?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/chtl_toolbar" 
android:layout_width="match_parent" 
android:layout_height="?android:actionBarSize"> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:orientation="horizontal"> 
    <ImageView 
     android:id="@+id/chtl_useIMG" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="right" 
     android:layout_marginRight="20dp" 
     android:src="@mipmap/ic_launcher" 
     android:visibility="visible" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Nilu" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Nilu" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Nilu" /> 
</LinearLayout> 
</android.support.v7.widget.Toolbar> 
abs_layout.xml
<?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="wrap_content" 
    android:orientation="vertical" > 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="@string/app_name" 
     android:textColor="#000000" 
     android:id="@+id/mytext" 
     android:textSize="15sp" /> 
</LinearLayout> 
Main.java
public class Problems extends AppCompatActivity {     @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.chtl_toolbar); 
    setSupportActionBar(toolbar); 
    } 
} 
Style.xml
<style name="AccountSetting" parent="Theme.AppCompat.Light.NoActionBar">     <!-- Customize your theme here. --> 
    <item name="colorPrimaryDark">#ffffff</item> 
    <item name="colorPrimary">#ffffff</item> 
</style> 
回答:
试试这个使用习惯Toolbar这样
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/chtl_toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?android:actionBarSize"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:orientation="horizontal"> 
     <ImageView 
      android:id="@+id/chtl_useIMG" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_marginRight="20dp" 
      android:src="@mipmap/ic_launcher_round" 
      android:visibility="visible" /> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Nilu" /> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Nilu" /> 
     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Nilu" /> 
    </LinearLayout> 
</android.support.v7.widget.Toolbar> 
比你onCreate()设置此工具栏为你的动作条活动方法
Toolbar toolbar = (Toolbar) findViewById(R.id.ar_toolbar); setSupportActionBar(toolbar); 
添加这个主题
<style name="AccountSetting" parent="Theme.AppCompat.Light.NoActionBar">     <!-- Customize your theme here. --> 
    <item name="colorPrimaryDark">@color/colorWhite</item> 
    <item name="colorPrimary">@color/colorWhite</item> 
</style> 
编辑你活动的问题布局添加此
<?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="wrap_content" 
    android:orientation="vertical" > 
    <include 
     layout="@layout/toolbarlayout"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="@string/app_name" 
     android:textColor="#000000" 
     android:id="@+id/mytext" 
     android:textSize="15sp" /> 
</LinearLayout> 
你的活动代码
public class Problems extends AppCompatActivity {     @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_layout); 
    LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View v = inflator.inflate(R.layout.custom_actionbar, null); 
    getSupportActionBar().setCustomView(v); 
    } 
} 
以上是 带按钮和标题的顶部导航栏 的全部内容, 来源链接: utcz.com/qa/261662.html






