【问题标题】:Action Bar with ImageView带有 ImageView 的操作栏
【发布时间】:2018-04-08 17:17:52
【问题描述】:

enter image description here 大家好你们好 我想将 3 个 ImageView 放在操作栏中,两个 ImageView 固定,一个做缩放动画,我尝试了几次,但我找不到我想要的解决方案,这是我正在使用的代码。请帮助我

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorBleu)));
    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowCustomEnabled(true);

   //desactive le titre d'action bar
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);


    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    assert inflator != null;
    View v = inflator.inflate(R.layout.custom_imageview, null);


    actionBar.setCustomView(v);
    AnimationSet animation = new AnimationSet(true);
    animation.addAnimation(new AlphaAnimation(0.0F, 1.0F));
    animation.addAnimation(new ScaleAnimation(0.8f, 1.5f, 0.8f, 1.5f));
    animation.setDuration(4000);
    v.startAnimation(animation);

【问题讨论】:

  • 尝试使用Toolbar,很容易设计UI。
  • thiks 你能解释一下吗
  • Toolbar或者ActionBar是不行的,需要自己做布局,应该很简单提示:android中工具栏的minHeight是56dp。

标签: android android-toolbar android-actionbar-compat


【解决方案1】:

只需使用工具栏而不是操作栏。 一些例子:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay">

   <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="horizontal">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/img1"
                android:src="@drawable/img1"/>
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/img2"
                android:src="@drawable/img2"/>
   </LinearLayout>
</android.support.v7.widget.Toolbar>

【讨论】:

    【解决方案2】:

    像上面写的@Aptem Komap 这样的布局。

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">
    
       <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="horizontal">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/img1"
                    android:src="@drawable/img1"/>
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/img2"
                    android:src="@drawable/img2"/>
       </LinearLayout>
    </android.support.v7.widget.Toolbar>
    

    活动中

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_profile_detail);
            Toolbar toolbar = findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
        }
    

    请注意,您的活动必须从 AppCompatActivity 扩展。 在 AndroidManifes.xml 中:

    <activity
                android:name=".MainActivity"
                android:theme="@style/AppTheme.NoActionBar"/>
    

    在styles.xml中

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

    【讨论】:

    • 这是什么“mToolbar”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多