質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Q&A

解決済

1回答

3465閲覧

AndroidStudio ActionBarを画面下に表示したい

退会済みユーザー

退会済みユーザー

総合スコア0

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

0グッド

0クリップ

投稿2020/05/09 15:17

実施したいこと

タイトル通りです。
常に画面上部に表示されているので画面下に表示したいです。
調べると消す方法は出てきますが移動させる方法がなかったので。

バージョン

ミニマムSDK:API28:Android9.0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hoshi-takanori

2020/05/09 18:10

ActionBar は非表示にして、Toolbar を使えばいいと思います。UI 的にどうなのかという疑問はありますが…。(なお、android.support.v7.widget.Toolbar は古いので androidx.appcompat.widget.Toolbar を使うことをお勧めします。) https://qiita.com/kobakei/items/f17019f8b0a88c8e57f4
退会済みユーザー

退会済みユーザー

2020/05/10 03:11

ありがとうございます。参考になりました。
guest

回答1

0

ベストアンサー

とりあえずアクションバーを消す方法

「AndroidManifest.xml」の[application]タグの要素[android:theme]を下記のように変更
変更前

xml

1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.program.toolbar"> 4 <application 5 android:allowBackup="true" 6 android:icon="@mipmap/ic_launcher" 7 android:label="@string/app_name" 8 android:roundIcon="@mipmap/ic_launcher_round" 9 android:supportsRtl="true" 10 android:theme="@style/AppTheme"> 11 <activity android:name=".MainActivity"> 12 <intent-filter> 13 <action android:name="android.intent.action.MAIN" /> 14 <category android:name="android.intent.category.LAUNCHER" /> 15 </intent-filter> 16 </activity> 17 </application> 18</manifest>

変更後

xml

1<?xml version="1.0" encoding="utf-8"?> 2<manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.program.toolbar"> 4 <application 5 android:allowBackup="true" 6 android:icon="@mipmap/ic_launcher" 7 android:label="@string/app_name" 8 android:roundIcon="@mipmap/ic_launcher_round" 9 android:supportsRtl="true" 10 android:theme="@style/Theme.AppCompat.Light.NoActionBar"> 11 <activity android:name=".MainActivity"> 12 <intent-filter> 13 <action android:name="android.intent.action.MAIN" /> 14 <category android:name="android.intent.category.LAUNCHER" /> 15 </intent-filter> 16 </activity> 17 </application> 18</manifest>

[AppTheme]って何かよくわからなかったが、次のファイルに記載されている情報のよう。
「res/values/styles.xml」

xml

1<resources> 2 <!-- Base application theme. --> 3 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 4 <!-- Customize your theme here. --> 5 <item name="colorPrimary">@color/colorPrimary</item> 6 <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 7 <item name="colorAccent">@color/colorAccent</item> 8 </style> 9</resources>

AppThemeはTheme.AppCompat.Light.DarkActionBarを継承?しているので
できるだけ近いTheme.AppCompat.Light.NoActionBarに変更した。
これだけでまずActionBarは表示されなくなりました。

下にアクションバーを表示する

GUIコンポーネントにToolbarというのがいるので配置する。
私の場合は下に配置したいのでConstraintLayoutの下にくっつけてます。
「activity_main.xml」

xml

1<?xml version="1.0" encoding="utf-8"?> 2<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 <TextView 9 android:id="@+id/textView" 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:text="Hello World!" 13 app:layout_constraintBottom_toBottomOf="parent" 14 app:layout_constraintLeft_toLeftOf="parent" 15 app:layout_constraintRight_toRightOf="parent" 16 app:layout_constraintTop_toTopOf="parent" /> 17 <androidx.appcompat.widget.Toolbar 18 android:id="@+id/toolbar" 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 android:background="?attr/colorPrimary" 22 android:minHeight="?attr/actionBarSize" 23 android:theme="@style/AppTheme" 24 app:layout_constraintBottom_toBottomOf="parent" 25 app:layout_constraintStart_toStartOf="parent" /> 26</androidx.constraintlayout.widget.ConstraintLayout>

「AndroidManifest.xml」にアクションバーを表示しないようにしているのでこれだけだと表示されませんでした。逆に表示するようにすれば上と下のどちらにも表示されました。
表示されるように「MainActivity.java」を修正。

java

1package com.program.toolbar; 2 3import android.os.Bundle; 4 5import androidx.appcompat.app.AppCompatActivity; 6import androidx.appcompat.widget.Toolbar; 7 8public class MainActivity extends AppCompatActivity { 9 10 @Override 11 protected void onCreate(Bundle savedInstanceState) { 12 super.onCreate(savedInstanceState); 13 setContentView(R.layout.activity_main); 14 15 Toolbar toolbar = findViewById(R.id.toolbar); 16 setSupportActionBar(toolbar); 17 } 18} 19

これで表示されました。
しかし、タイトルの文字色が変わってましたのでどこか間違っているか、
もしくはそういうものなのかもしれません。一応タイトル文字色を変える方法

java

1Toolbar toolbar = findViewById(R.id.toolbar); 2toolbar.setTitleTextColor(Color.parseColor("white")); 3setSupportActionBar(toolbar);

元の色が何色かはわからなかったのでとりあえず似ている白にしました。

バージョン

ミニマムSDK:API28:Android9.0
Android Studio:3.6.3

投稿2020/05/10 03:08

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問